Skip to content

Commit cb888bb

Browse files
peffgitster
authored andcommitted
repack: free geometry struct
When the program is ending, we call clear_pack_geometry() to free any resources in the pack_geometry struct. But the struct itself is allocated on the heap, and leak-checkers will complain about the resulting small leak. This one was marked by Coverity as a "new" leak, though it has existed since 0fabafd (builtin/repack.c: add '--geometric' option, 2021-02-22). This might be because recent unrelated changes in the file confused it about what is new and what is not. But regardless, it is worth addressing. We can fix it easily by free-ing the struct. We'll convert our "clear" function to "free", since the allocation happens in the matching init() function (though since there is only one call to each, and the struct is local to this file, it's mostly academic). Another option would be to put the struct on the stack rather than the heap. However, this gets tricky, as we check the pointer against NULL in several places to decide whether we're in geometric mode. Signed-off-by: Jeff King <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a82fb66 commit cb888bb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

builtin/repack.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,13 @@ static struct packed_git *get_preferred_pack(struct pack_geometry *geometry)
492492
return NULL;
493493
}
494494

495-
static void clear_pack_geometry(struct pack_geometry *geometry)
495+
static void free_pack_geometry(struct pack_geometry *geometry)
496496
{
497497
if (!geometry)
498498
return;
499499

500500
free(geometry->pack);
501-
geometry->pack_nr = 0;
502-
geometry->pack_alloc = 0;
503-
geometry->split = 0;
501+
free(geometry);
504502
}
505503

506504
struct midx_snapshot_ref_data {
@@ -1228,7 +1226,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12281226
string_list_clear(&names, 1);
12291227
string_list_clear(&existing_nonkept_packs, 0);
12301228
string_list_clear(&existing_kept_packs, 0);
1231-
clear_pack_geometry(geometry);
1229+
free_pack_geometry(geometry);
12321230

12331231
return ret;
12341232
}

0 commit comments

Comments
 (0)