Skip to content

Commit 95875e0

Browse files
committed
Merge branch 'jt/commit-graph-plug-memleak'
Fix a leak noticed by fuzzer. * jt/commit-graph-plug-memleak: commit-graph: avoid memory leaks
2 parents 6de1630 + fbda77c commit 95875e0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

commit-graph.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
281281
if (data + graph_size - chunk_lookup <
282282
GRAPH_CHUNKLOOKUP_WIDTH) {
283283
error(_("commit-graph chunk lookup table entry missing; file may be incomplete"));
284-
free(graph);
285-
return NULL;
284+
goto free_and_return;
286285
}
287286

288287
chunk_id = get_be32(chunk_lookup + 0);
@@ -293,8 +292,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
293292
if (chunk_offset > graph_size - the_hash_algo->rawsz) {
294293
error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
295294
(uint32_t)chunk_offset);
296-
free(graph);
297-
return NULL;
295+
goto free_and_return;
298296
}
299297

300298
switch (chunk_id) {
@@ -361,8 +359,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
361359

362360
if (chunk_repeated) {
363361
error(_("commit-graph chunk id %08x appears multiple times"), chunk_id);
364-
free(graph);
365-
return NULL;
362+
goto free_and_return;
366363
}
367364

368365
if (last_chunk_id == GRAPH_CHUNKID_OIDLOOKUP)
@@ -381,17 +378,20 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
381378
/* We need both the bloom chunks to exist together. Else ignore the data */
382379
graph->chunk_bloom_indexes = NULL;
383380
graph->chunk_bloom_data = NULL;
384-
graph->bloom_filter_settings = NULL;
381+
FREE_AND_NULL(graph->bloom_filter_settings);
385382
}
386383

387384
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
388385

389-
if (verify_commit_graph_lite(graph)) {
390-
free(graph);
391-
return NULL;
392-
}
386+
if (verify_commit_graph_lite(graph))
387+
goto free_and_return;
393388

394389
return graph;
390+
391+
free_and_return:
392+
free(graph->bloom_filter_settings);
393+
free(graph);
394+
return NULL;
395395
}
396396

397397
static struct commit_graph *load_commit_graph_one(const char *graph_file,

0 commit comments

Comments
 (0)