fix leaks in tog's queue_commits()
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/tog/tog.c b/tog/tog.c
index db7cd78..050df20 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -344,6 +344,7 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
struct got_object_id *id;
struct commit_queue_entry *entry;
int nfetched, nqueued = 0, found_obj = 0;
+ int is_root_path = strcmp(path, "/") == 0;
err = got_commit_graph_iter_start(graph, start_id);
if (err)
@@ -387,13 +388,14 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
if (err)
break;
- if (path) {
+ if (!is_root_path) {
struct got_object *obj;
struct got_object_qid *pid;
int changed = 0;
err = got_object_open_by_path(&obj, repo, id, path);
if (err) {
+ got_object_commit_close(commit);
if (err->code == GOT_ERR_NO_OBJ &&
(found_obj || !init)) {
/* History stops here. */
@@ -411,6 +413,7 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
if (err) {
if (err->code != GOT_ERR_NO_OBJ) {
got_object_close(obj);
+ got_object_commit_close(commit);
break;
}
err = NULL;
@@ -420,12 +423,16 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
id = got_object_get_id(obj);
if (id == NULL) {
err = got_error_from_errno();
+ got_object_close(obj);
+ got_object_close(pobj);
break;
}
pid = got_object_get_id(pobj);
if (pid == NULL) {
err = got_error_from_errno();
free(id);
+ got_object_close(obj);
+ got_object_close(pobj);
break;
}
changed =
@@ -435,6 +442,7 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
free(pid);
}
}
+ got_object_close(obj);
if (!changed) {
got_object_commit_close(commit);
continue;