plug memory leaks in advance_branch()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 7ca2aa5..f1b2429 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -294,7 +294,7 @@ advance_branch(struct got_commit_graph *graph,
* which do not contribute any content to this path.
*/
if (is_merge_point(node) && !got_path_is_root_dir(graph->path)) {
- struct got_object_id *id, *merged_id, *prev_id = NULL;
+ struct got_object_id *merged_id, *prev_id = NULL;
int branches_differ = 0;
err = got_object_id_by_path(&merged_id, repo, commit_id,
@@ -303,6 +303,8 @@ advance_branch(struct got_commit_graph *graph,
return err;
SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) {
+ struct got_object_id *id;
+
if (got_object_idset_get(graph->node_ids, qid->id))
continue; /* parent already traversed */
@@ -313,6 +315,8 @@ advance_branch(struct got_commit_graph *graph,
branches_differ = 1;
continue;
}
+ free(merged_id);
+ free(prev_id);
return err;
}
@@ -320,8 +324,9 @@ advance_branch(struct got_commit_graph *graph,
if (!branches_differ &&
got_object_id_cmp(merged_id, prev_id) != 0)
branches_differ = 1;
- } else
- prev_id = id;
+ free(prev_id);
+ }
+ prev_id = id;
/*
* If a branch has created the merged content we can
@@ -330,10 +335,17 @@ advance_branch(struct got_commit_graph *graph,
if (got_object_id_cmp(merged_id, id) == 0) {
err = got_object_idset_add(graph->open_branches,
qid->id, node);
+ free(merged_id);
+ free(id);
return err;
}
}
+ free(prev_id);
+ prev_id = NULL;
+ free(merged_id);
+ merged_id = NULL;
+
/*
* If the path's content is the same on all branches,
* follow the first parent only.