commit 3f69050e707b0f3c73aecf3053782433bc7b328b from: Kyle Ackerman via: Thomas Adam date: Wed Nov 22 22:48:01 2023 UTC fix memory leak on error in got_privsep_recv_painted_commits() Diff from Kyle Ackerman, thank you! I've added a imsg_free() call before the break too. commit - 16753fcd1c448414735e656a5c4a33048d93d029 commit + 3f69050e707b0f3c73aecf3053782433bc7b328b blob - bc5e676055fe92ff94c40e173d0897a7b49775cf blob + 3717110f5337e4659153cce6010a8b8709da0104 --- lib/privsep.c +++ lib/privsep.c @@ -3510,22 +3510,32 @@ got_privsep_recv_painted_commits(struct got_object_id_ for (;;) { err = got_privsep_recv_imsg(&imsg, ibuf, 0); - if (err) + if (err){ + imsg_free(&imsg); return err; + } datalen = imsg.hdr.len - IMSG_HEADER_SIZE; - if (imsg.hdr.type == GOT_IMSG_COMMIT_PAINTING_DONE) - break; - if (imsg.hdr.type != GOT_IMSG_PAINTED_COMMITS) + if (imsg.hdr.type == GOT_IMSG_COMMIT_PAINTING_DONE) { + imsg_free(&imsg); + break; + } + if (imsg.hdr.type != GOT_IMSG_PAINTED_COMMITS){ + imsg_free(&imsg); return got_error(GOT_ERR_PRIVSEP_MSG); + } - if (datalen < sizeof(icommits)) + if (datalen < sizeof(icommits)){ + imsg_free(&imsg); return got_error(GOT_ERR_PRIVSEP_LEN); + } memcpy(&icommits, imsg.data, sizeof(icommits)); if (icommits.ncommits * sizeof(icommit) < icommits.ncommits || datalen < sizeof(icommits) + - icommits.ncommits * sizeof(icommit)) + icommits.ncommits * sizeof(icommit)){ + imsg_free(&imsg); return got_error(GOT_ERR_PRIVSEP_LEN); + } for (i = 0; i < icommits.ncommits; i++) { memcpy(&icommit,