Browse Source

Merge branch 'ds/commit-graph-leakfix'

Code clean-up.

* ds/commit-graph-leakfix:
  commit-graph: reduce initial oid allocation
  builtin/commit-graph.c: UNLEAK variables
  commit-graph: clean up leaked memory during write
maint
Junio C Hamano 6 years ago
parent
commit
d4cd2dd214
  1. 11
      builtin/commit-graph.c
  2. 16
      commit-graph.c

11
builtin/commit-graph.c

@ -64,6 +64,7 @@ static int graph_verify(int argc, const char **argv) @@ -64,6 +64,7 @@ static int graph_verify(int argc, const char **argv)
if (!graph)
return 0;

UNLEAK(graph);
return verify_commit_graph(the_repository, graph);
}

@ -89,10 +90,8 @@ static int graph_read(int argc, const char **argv) @@ -89,10 +90,8 @@ static int graph_read(int argc, const char **argv)
graph_name = get_commit_graph_filename(opts.obj_dir);
graph = load_commit_graph_one(graph_name);

if (!graph) {
UNLEAK(graph_name);
if (!graph)
die("graph file %s does not exist", graph_name);
}

FREE_AND_NULL(graph_name);

@ -115,7 +114,7 @@ static int graph_read(int argc, const char **argv) @@ -115,7 +114,7 @@ static int graph_read(int argc, const char **argv)
printf(" large_edges");
printf("\n");

free_commit_graph(graph);
UNLEAK(graph);

return 0;
}
@ -170,6 +169,8 @@ static int graph_write(int argc, const char **argv) @@ -170,6 +169,8 @@ static int graph_write(int argc, const char **argv)
pack_indexes = &lines;
if (opts.stdin_commits)
commit_hex = &lines;

UNLEAK(buf);
}

write_commit_graph(opts.obj_dir,
@ -178,7 +179,7 @@ static int graph_write(int argc, const char **argv) @@ -178,7 +179,7 @@ static int graph_write(int argc, const char **argv)
opts.append,
1);

string_list_clear(&lines, 0);
UNLEAK(lines);
return 0;
}


16
commit-graph.c

@ -739,11 +739,12 @@ static int add_ref_to_list(const char *refname, @@ -739,11 +739,12 @@ static int add_ref_to_list(const char *refname,
void write_commit_graph_reachable(const char *obj_dir, int append,
int report_progress)
{
struct string_list list;
struct string_list list = STRING_LIST_INIT_DUP;

string_list_init(&list, 1);
for_each_ref(add_ref_to_list, &list);
write_commit_graph(obj_dir, NULL, &list, append, report_progress);

string_list_clear(&list, 0);
}

void write_commit_graph(const char *obj_dir,
@ -768,7 +769,7 @@ void write_commit_graph(const char *obj_dir, @@ -768,7 +769,7 @@ void write_commit_graph(const char *obj_dir,
return;

oids.nr = 0;
oids.alloc = approximate_object_count() / 4;
oids.alloc = approximate_object_count() / 32;
oids.progress = NULL;
oids.progress_done = 0;

@ -813,6 +814,7 @@ void write_commit_graph(const char *obj_dir, @@ -813,6 +814,7 @@ void write_commit_graph(const char *obj_dir,
die(_("error opening index for %s"), packname.buf);
for_each_object_in_pack(p, add_packed_commits, &oids, 0);
close_pack(p);
free(p);
}
stop_progress(&oids.progress);
strbuf_release(&packname);
@ -895,9 +897,11 @@ void write_commit_graph(const char *obj_dir, @@ -895,9 +897,11 @@ void write_commit_graph(const char *obj_dir,
compute_generation_numbers(&commits, report_progress);

graph_name = get_commit_graph_filename(obj_dir);
if (safe_create_leading_directories(graph_name))
if (safe_create_leading_directories(graph_name)) {
UNLEAK(graph_name);
die_errno(_("unable to create leading directories of %s"),
graph_name);
}

hold_lock_file_for_update(&lk, graph_name, LOCK_DIE_ON_ERROR);
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
@ -942,9 +946,9 @@ void write_commit_graph(const char *obj_dir, @@ -942,9 +946,9 @@ void write_commit_graph(const char *obj_dir,
finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
commit_lock_file(&lk);

free(graph_name);
free(commits.list);
free(oids.list);
oids.alloc = 0;
oids.nr = 0;
}

#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2

Loading…
Cancel
Save