]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: free packing_data in more places
authorTaylor Blau <me@ttaylorr.com>
Thu, 14 Dec 2023 22:23:39 +0000 (17:23 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Dec 2023 22:38:07 +0000 (14:38 -0800)
The pack-objects internals use a packing_data struct to track what
objects are part of the pack(s) being formed.

Since these structures contain allocated fields, failing to
appropriately free() them results in a leak. Plug that leak by
introducing a clear_packing_data() function, and call it in the
appropriate spots.

This is a fairly straightforward leak to plug, since none of the callers
expect to read any values or have any references to parts of the address
space being freed.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
midx.c
pack-objects.c
pack-objects.h

index 89a8b5a9768e42da3edaaddb63a663936ef70576..321d7effb02195f4367eb37f050f557df067350e 100644 (file)
@@ -4522,6 +4522,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                           reuse_packfile_objects);
 
 cleanup:
+       clear_packing_data(&to_pack);
        list_objects_filter_release(&filter_options);
        strvec_clear(&rp);
 
diff --git a/midx.c b/midx.c
index 1d14661dade4a686b1b18c351c55275b2a388ee3..778dd536c8d087e5f62c8433690bf9dfe2dd014c 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -1603,8 +1603,13 @@ static int write_midx_internal(const char *object_dir,
                                      flags) < 0) {
                        error(_("could not write multi-pack bitmap"));
                        result = 1;
+                       clear_packing_data(&pdata);
+                       free(commits);
                        goto cleanup;
                }
+
+               clear_packing_data(&pdata);
+               free(commits);
        }
        /*
         * NOTE: Do not use ctx.entries beyond this point, since it might
index f403ca6986a9d4c68715c1e1b24462d462fb8aa9..a9d9855063aea85f4b1b8f70f301c644c5d5e225 100644 (file)
@@ -151,6 +151,21 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
        init_recursive_mutex(&pdata->odb_lock);
 }
 
+void clear_packing_data(struct packing_data *pdata)
+{
+       if (!pdata)
+               return;
+
+       free(pdata->cruft_mtime);
+       free(pdata->in_pack);
+       free(pdata->in_pack_by_idx);
+       free(pdata->in_pack_pos);
+       free(pdata->index);
+       free(pdata->layer);
+       free(pdata->objects);
+       free(pdata->tree_depth);
+}
+
 struct object_entry *packlist_alloc(struct packing_data *pdata,
                                    const struct object_id *oid)
 {
index 0d78db40cb2f11fcbc4b3c2bbb2d23624ef3f22e..b9898a4e64b8b4d53b21ea776c16f79d9794efef 100644 (file)
@@ -169,6 +169,7 @@ struct packing_data {
 };
 
 void prepare_packing_data(struct repository *r, struct packing_data *pdata);
+void clear_packing_data(struct packing_data *pdata);
 
 /* Protect access to object database */
 static inline void packing_data_lock(struct packing_data *pdata)