commit 5a6829a24229eb0dfb73fdb62bcc65ea6333ac1b from: Kyle Ackerman via: Thomas Adam date: Thu Nov 14 16:16:05 2024 UTC plug memory leaks in 'got fetch' and 'got send' Check for duplicate items added to pathlists, and free associated data in case we were attempting to add a duplicate. Patch by: Kyle Ackerman commit - 4e35f3f5e6cd19658dea0cee4657bf3f209f1e64 commit + 5a6829a24229eb0dfb73fdb62bcc65ea6333ac1b blob - 182c2bc8c30708ec979efaabbb3d81839f514df9 blob + 5eef14a20c2095f7d3e35d90b6f6c9df86504786 --- lib/fetch.c +++ lib/fetch.c @@ -308,9 +308,11 @@ got_fetch_pack(struct got_object_id **pack_hash, struc if (packfile_size_cur <= ssizeof(pack_hdr) + SHA1_DIGEST_LENGTH) packfile_size_cur = 0; if (!done && refname && id) { - err = got_pathlist_insert(NULL, refs, refname, id); + err = got_pathlist_insert(&pe, refs, refname, id); if (err) goto done; + if (pe == NULL) + free(id); } else if (!done && server_progress) { char *p; /* blob - 746c2864eb29a5a281a4c584b7a025275d80fff6 blob + 2b7c36baf89ab7470fda3802cbe1bf5fcea0195f --- lib/send.c +++ lib/send.c @@ -168,6 +168,7 @@ insert_sendable_ref(struct got_pathlist_head *refs, co const struct got_error *err; struct got_reference *ref; struct got_object_id *id = NULL; + struct got_pathlist_entry *new = NULL; int obj_type; err = got_ref_open(&ref, repo, refname, 0); @@ -196,11 +197,11 @@ insert_sendable_ref(struct got_pathlist_head *refs, co goto done; } - err = got_pathlist_insert(NULL, refs, target_refname, id); + err = got_pathlist_insert(&new, refs, target_refname, id); done: if (ref) got_ref_close(ref); - if (err) + if (err || new == NULL /* duplicate */) free(id); return err; }