Skip to content

Commit 66f0c71

Browse files
ttaylorrgitster
authored andcommitted
pack-objects: free packing_data in more places
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a87c84 commit 66f0c71

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,6 +4522,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
45224522
reuse_packfile_objects);
45234523

45244524
cleanup:
4525+
clear_packing_data(&to_pack);
45254526
list_objects_filter_release(&filter_options);
45264527
strvec_clear(&rp);
45274528

midx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,13 @@ static int write_midx_internal(const char *object_dir,
16031603
flags) < 0) {
16041604
error(_("could not write multi-pack bitmap"));
16051605
result = 1;
1606+
clear_packing_data(&pdata);
1607+
free(commits);
16061608
goto cleanup;
16071609
}
1610+
1611+
clear_packing_data(&pdata);
1612+
free(commits);
16081613
}
16091614
/*
16101615
* NOTE: Do not use ctx.entries beyond this point, since it might

pack-objects.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
151151
init_recursive_mutex(&pdata->odb_lock);
152152
}
153153

154+
void clear_packing_data(struct packing_data *pdata)
155+
{
156+
if (!pdata)
157+
return;
158+
159+
free(pdata->cruft_mtime);
160+
free(pdata->in_pack);
161+
free(pdata->in_pack_by_idx);
162+
free(pdata->in_pack_pos);
163+
free(pdata->index);
164+
free(pdata->layer);
165+
free(pdata->objects);
166+
free(pdata->tree_depth);
167+
}
168+
154169
struct object_entry *packlist_alloc(struct packing_data *pdata,
155170
const struct object_id *oid)
156171
{

pack-objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct packing_data {
169169
};
170170

171171
void prepare_packing_data(struct repository *r, struct packing_data *pdata);
172+
void clear_packing_data(struct packing_data *pdata);
172173

173174
/* Protect access to object database */
174175
static inline void packing_data_lock(struct packing_data *pdata)

0 commit comments

Comments
 (0)