aboutsummaryrefslogtreecommitdiffstats
path: root/ui-tree.c
diff options
context:
space:
mode:
authorLukas Fleischer2013-03-04 13:25:36 +0100
committerJason A. Donenfeld2013-03-04 20:47:53 -0500
commit985d6ca7e70ca4774b81106e9eeecd619e5b3930 (patch)
tree2ef4b0d2c4be846266619ba70ae6267d26c94726 /ui-tree.c
parent0ffdc46f0830d89e32204e1b30145b4c26727e6c (diff)
downloadcgit-985d6ca7e70ca4774b81106e9eeecd619e5b3930.tar.gz
cgit-985d6ca7e70ca4774b81106e9eeecd619e5b3930.tar.bz2
cgit-985d6ca7e70ca4774b81106e9eeecd619e5b3930.zip
cgit_print_tree(): Free curr_rev after usage
Fixes following memory leak seen with "PATH_INFO=/cgit/tree/": ==15715== 7 bytes in 1 blocks are definitely lost in loss record 4 of 51 ==15715== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==15715== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==15715== by 0x46CAA8: xstrdup (wrapper.c:35) ==15715== by 0x418A4C: cgit_print_tree (ui-tree.c:274) ==15715== by 0x407D91: tree_fn (cmd.c:131) ==15715== by 0x405E16: process_request (cgit.c:574) ==15715== by 0x4074C8: cache_process (cache.c:322) ==15715== by 0x406C4F: main (cgit.c:872) Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ui-tree.c b/ui-tree.c
index 561f9e7..b692b56 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -271,7 +271,6 @@ void cgit_print_tree(const char *rev, char *path)
271 if (!rev) 271 if (!rev)
272 rev = ctx.qry.head; 272 rev = ctx.qry.head;
273 273
274 walk_tree_ctx.curr_rev = xstrdup(rev);
275 if (get_sha1(rev, sha1)) { 274 if (get_sha1(rev, sha1)) {
276 cgit_print_error(fmt("Invalid revision name: %s", rev)); 275 cgit_print_error(fmt("Invalid revision name: %s", rev));
277 return; 276 return;
@@ -282,12 +281,17 @@ void cgit_print_tree(const char *rev, char *path)
282 return; 281 return;
283 } 282 }
284 283
284 walk_tree_ctx.curr_rev = xstrdup(rev);
285
285 if (path == NULL) { 286 if (path == NULL) {
286 ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); 287 ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx);
287 return; 288 goto cleanup;
288 } 289 }
289 290
290 read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 291 read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
291 if (walk_tree_ctx.state == 1) 292 if (walk_tree_ctx.state == 1)
292 ls_tail(); 293 ls_tail();
294
295cleanup:
296 free(walk_tree_ctx.curr_rev);
293} 297}