commit 77968bb039a04d0243df811be0423030770e2696be962859269f46d0509744b8 from: Stefan Sperling date: Tue Feb 24 19:56:50 2026 UTC fix a double-free on error in got_pack_paint_commits() Before heading out on error, clear the qid pointer if we have not yet removed qid from the list. Otherwise the error path will free the qid while it is still on the list. Also garbage collect the qid0 pointer which has been unused for some time. ok op@ commit - 533142c736712c1e29f7dc8ddf2e9d9f31ddef5af0dbb06ba9b7192f9ce88279 commit + 77968bb039a04d0243df811be0423030770e2696be962859269f46d0509744b8 blob - 4b45640f7a551eb6db57d7e42b34d046258c9f69d12ae456ab227e83299f39d6 blob + 601cadf2a8240757756bac88a756f304670e91b879f951b36ce28b2860d712ff --- lib/pack_create_privsep.c +++ lib/pack_create_privsep.c @@ -211,7 +211,6 @@ struct recv_painted_commit_arg { struct got_ratelimit *rl; got_cancel_cb cancel_cb; void *cancel_arg; - struct got_object_qid **qid0; }; static const struct got_error * @@ -276,8 +275,7 @@ recv_painted_commit(void *arg, struct got_object_id *i } static const struct got_error * -paint_packed_commits(struct got_object_qid **qid0, - struct got_pack *pack, intptr_t color, +paint_packed_commits(struct got_pack *pack, intptr_t color, int *ncolored, int *nqueued, int *nskip, struct got_object_id_queue *ids, struct got_object_idset *keep, struct got_object_idset *drop, struct got_object_idset *skip, struct got_repository *repo, @@ -312,7 +310,6 @@ paint_packed_commits(struct got_object_qid **qid0, arg.rl = rl; arg.cancel_cb = cancel_cb; arg.cancel_arg = cancel_arg; - arg.qid0 = qid0; err = got_privsep_recv_painted_commits(&next_ids, recv_painted_commit, &arg, pack->privsep_child->ibuf); if (err) @@ -428,34 +425,41 @@ got_pack_paint_commits(int *ncolored, struct got_objec if (idx != -1) { err = got_privsep_init_commit_painting( pack->privsep_child->ibuf); - if (err) + if (err) { + qid = NULL; goto done; + } err = send_idset(pack->privsep_child->ibuf, keep); - if (err) + if (err) { + qid = NULL; goto done; + } err = send_idset(pack->privsep_child->ibuf, drop); - if (err) + if (err) { + qid = NULL; goto done; + } err = send_idset(pack->privsep_child->ibuf, skip); - if (err) + if (err) { + qid = NULL; goto done; - err = paint_packed_commits(&qid, pack, + } + err = paint_packed_commits(pack, color, ncolored, &nqueued, &nskip, ids, keep, drop, skip, repo, progress_cb, progress_arg, rl, cancel_cb, cancel_arg); - if (qid) { - STAILQ_REMOVE(ids, qid, - got_object_qid, entry); - nqueued--; - got_object_qid_free(qid); + if (err) { qid = NULL; - } - if (err) goto done; + } + STAILQ_REMOVE(ids, qid, got_object_qid, entry); + nqueued--; + got_object_qid_free(qid); + qid = NULL; continue; } }