diff options
author | Lukas Fleischer | 2013-03-04 13:25:35 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2013-03-04 19:55:34 -0500 |
commit | 0ffdc46f0830d89e32204e1b30145b4c26727e6c (patch) | |
tree | 8596030d3926a8dd3ed13d7a2704acc2401dd907 | |
parent | fab385ef5ca516dcda79df87eb926eccdda64a54 (diff) | |
download | cgit-0ffdc46f0830d89e32204e1b30145b4c26727e6c.tar.gz cgit-0ffdc46f0830d89e32204e1b30145b4c26727e6c.tar.bz2 cgit-0ffdc46f0830d89e32204e1b30145b4c26727e6c.zip |
find_default_branch(): Free refmatch after usage
Fixes following memory leak seen with "PATH_INFO=/cgit/refs/":
==13408== 7 bytes in 1 blocks are definitely lost in loss record 4 of 52
==13408== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13408== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so)
==13408== by 0x46CA78: xstrdup (wrapper.c:35)
==13408== by 0x405840: find_current_ref (cgit.c:426)
==13408== by 0x44BE5A: do_one_ref (refs.c:527)
==13408== by 0x44D3E0: do_for_each_ref_in_dir (refs.c:553)
==13408== by 0x44D85A: do_for_each_ref (refs.c:1298)
==13408== by 0x405889: find_default_branch (cgit.c:438)
==13408== by 0x405AC4: prepare_repo_cmd (cgit.c:490)
==13408== by 0x405D97: process_request (cgit.c:557)
==13408== by 0x407490: cache_process (cache.c:322)
==13408== by 0x406C18: main (cgit.c:864)
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r-- | cgit.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -427,6 +427,12 @@ static int find_current_ref(const char *refname, const unsigned char *sha1, | |||
427 | return info->match; | 427 | return info->match; |
428 | } | 428 | } |
429 | 429 | ||
430 | static void free_refmatch_inner(struct refmatch *info) | ||
431 | { | ||
432 | if (info->first_ref) | ||
433 | free(info->first_ref); | ||
434 | } | ||
435 | |||
430 | static char *find_default_branch(struct cgit_repo *repo) | 436 | static char *find_default_branch(struct cgit_repo *repo) |
431 | { | 437 | { |
432 | struct refmatch info; | 438 | struct refmatch info; |
@@ -442,6 +448,8 @@ static char *find_default_branch(struct cgit_repo *repo) | |||
442 | ref = info.first_ref; | 448 | ref = info.first_ref; |
443 | if (ref) | 449 | if (ref) |
444 | ref = xstrdup(ref); | 450 | ref = xstrdup(ref); |
451 | free_refmatch_inner(&info); | ||
452 | |||
445 | return ref; | 453 | return ref; |
446 | } | 454 | } |
447 | 455 | ||