commit 7a9b1c13f55a6aa3392ccc4a59ba7dc278c2683a from: Stefan Sperling date: Sat Dec 28 13:33:06 2024 UTC store ibuf used by got_patch() on the stack rather than the heap commit - ad3f6569ebcf5e03dcdb20e07b0339a8429388b8 commit + 7a9b1c13f55a6aa3392ccc4a59ba7dc278c2683a blob - 6585749c44d27fcfe5870429cad2f6748af20bc4 blob + edb26e01b7ce7ae6f0582ad4b4cb1a56c500e3d4 --- 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)