Commit Diff


commit - 0ec6f014868a19fd2289c5adeb63767dec547c15
commit + 62f591725a7d7477ca00fed09795d566f0af4095
blob - 9f38a2a67a7c0f2f7d1aeb96245c3a901798be0f
blob + 897760fc4691f3b9afbe4f60833c72a447cda40c
--- lib/diff3.c
+++ lib/diff3.c
@@ -265,7 +265,7 @@ done:
  * For merge(1).
  */
 const struct got_error *
-merge_diff3(BUF **buf, char *p1, char *p2, char *p3, int flags)
+merge_diff3(int outfd, char *p1, char *p2, char *p3, int flags)
 {
 	const struct got_error *err = NULL;
 	char *dp13, *dp23, *path1, *path2, *path3;
@@ -276,8 +276,6 @@ merge_diff3(BUF **buf, char *p1, char *p2, char *p3, i
 	struct diff3_state *d3s;
 	int i;
 
-	*buf = NULL;
-
 	d3s = calloc(1, sizeof(*d3s));
 	if (d3s == NULL)
 		return got_error_from_errno();
@@ -405,8 +403,11 @@ out:
 			fclose(d3s->fp[i]);
 	}
 	free(d3s);
-	if (err == NULL)
-		*buf = diffb;
+	if (err == NULL) {
+		if (buf_write_fd(diffb, outfd) < 0)
+			err = got_error_from_errno();
+	}
+	buf_free(diffb);
 	return err;
 }