Commit Diff


commit - a966183f12546a7832602b3a25db7384660951d9fe66ee5d733de24ebf2665e6
commit + e06f726988f1ba79878783300e73db2564643823dd9d0ced9f28f098a1175e2d
blob - ef3a9db75044c6f7d79d6b6a0da8ef8a45000839bea8c622222e02e2a8c451df
blob + b10269e23efc106473df2aded5b2d4744c24f234ebed253756c66a0dce110521
--- lib/patch.c	
+++ lib/patch.c	
@@ -1045,16 +1045,12 @@ got_patch(int fd, struct got_worktree *worktree, struc
 	struct got_tree_object *tree = NULL;
 	char *fileindex_path = NULL;
 	char *oldpath, *newpath;
-	struct imsgbuf *ibuf;
+	struct imsgbuf ibuf;
 	int imsg_fds[2] = {-1, -1};
 	int overlapcnt, done = 0, failed = 0;
 	pid_t pid;
 
-	ibuf = calloc(1, sizeof(*ibuf));
-	if (ibuf == NULL) {
-		err = got_error_from_errno("calloc");
-		goto done;
-	}
+	memset(&ibuf, 0, sizeof(ibuf));
 
 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
 		err = got_error_from_errno("socketpair");
@@ -1076,13 +1072,13 @@ got_patch(int fd, struct got_worktree *worktree, struc
 		goto done;
 	}
 	imsg_fds[1] = -1;
-	if (imsgbuf_init(ibuf, imsg_fds[0]) == -1) {
+	if (imsgbuf_init(&ibuf, imsg_fds[0]) == -1) {
 		err = got_error_from_errno("imsgbuf_init");
 		goto done;
 	}
-	imsgbuf_allow_fdpass(ibuf);
+	imsgbuf_allow_fdpass(&ibuf);
 
-	err = send_patch(ibuf, fd);
+	err = send_patch(&ibuf, fd);
 	fd = -1;
 	if (err)
 		goto done;
@@ -1110,7 +1106,7 @@ got_patch(int fd, struct got_worktree *worktree, struc
 		pa.progress_arg = progress_arg;
 		pa.head = &p.head;
 
-		err = recv_patch(ibuf, &done, &p, strip);
+		err = recv_patch(&ibuf, &done, &p, strip);
 		if (err || done)
 			break;
 
@@ -1154,10 +1150,8 @@ done:
 		got_object_commit_close(commit);
 	if (fd != -1 && close(fd) == -1 && err == NULL)
 		err = got_error_from_errno("close");
-	if (ibuf != NULL) {
-		imsgbuf_clear(ibuf);
-		free(ibuf);
-	}
+	if (ibuf.w)
+		imsgbuf_clear(&ibuf);
 	if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
 		err = got_error_from_errno("close");
 	if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)