From 1268afe83692cb8a9ea839ab979d82458da2d03d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:33 +0100 Subject: Free reflists after usage Free reflists in cgit_print_branches() and in cgit_print_tags() before returning reflist structures to the stack. This fixes following memory leaks seen with "PATH_INFO=/cgit/refs/": ==5710== 1,312 (32 direct, 1,280 indirect) bytes in 1 blocks are definitely lost in loss record 63 of 71 ==5710== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x4C2C2FF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x46CA9B: xrealloc (wrapper.c:100) ==5710== by 0x40AAA6: cgit_add_ref (shared.c:156) ==5710== by 0x40ABC4: cgit_refs_cb (shared.c:186) ==5710== by 0x44BCBA: do_one_ref (refs.c:527) ==5710== by 0x44D240: do_for_each_ref_in_dir (refs.c:553) ==5710== by 0x44D6BA: do_for_each_ref (refs.c:1298) ==5710== by 0x410FE2: cgit_print_branches (ui-refs.c:191) ==5710== by 0x4111E9: cgit_print_refs (ui-refs.c:244) ==5710== by 0x407C85: refs_fn (cmd.c:105) ==5710== by 0x405DDF: process_request (cgit.c:566) ==5710== ==5710== 6,846 (256 direct, 6,590 indirect) bytes in 1 blocks are definitely lost in loss record 68 of 71 ==5710== at 0x4C2C25E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x46CA9B: xrealloc (wrapper.c:100) ==5710== by 0x40AAA6: cgit_add_ref (shared.c:156) ==5710== by 0x40ABC4: cgit_refs_cb (shared.c:186) ==5710== by 0x44BCBA: do_one_ref (refs.c:527) ==5710== by 0x44D240: do_for_each_ref_in_dir (refs.c:553) ==5710== by 0x44D6EC: do_for_each_ref (refs.c:1288) ==5710== by 0x4110D5: cgit_print_tags (ui-refs.c:218) ==5710== by 0x4111FD: cgit_print_refs (ui-refs.c:246) ==5710== by 0x407C85: refs_fn (cmd.c:105) ==5710== by 0x405DDF: process_request (cgit.c:566) ==5710== by 0x407490: cache_process (cache.c:322) Signed-off-by: Lukas Fleischer --- ui-refs.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index ce06b08..4a9b8d3 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -205,6 +205,8 @@ void cgit_print_branches(int maxcount) if (maxcount < list.count) print_refs_link("heads"); + + cgit_free_reflist_inner(&list); } void cgit_print_tags(int maxcount) @@ -229,6 +231,8 @@ void cgit_print_tags(int maxcount) if (maxcount < list.count) print_refs_link("tags"); + + cgit_free_reflist_inner(&list); } void cgit_print_refs() -- cgit v1.2.3-70-g09d2 From fab385ef5ca516dcda79df87eb926eccdda64a54 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:34 +0100 Subject: print_tag_downloads(): Free ref variable Make sure the ref variable is freed if we build a "$basename-$version"-style ref. This fixes following memory leak seen with "PATH_INFO=/cgit/refs/": ==8784== 323 bytes in 29 blocks are definitely lost in loss record 41 of 53 ==8784== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==8784== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==8784== by 0x46CA28: xstrdup (wrapper.c:35) ==8784== by 0x410DA6: print_tag_downloads (ui-refs.c:115) ==8784== by 0x410F02: print_tag (ui-refs.c:141) ==8784== by 0x41128B: cgit_print_tags (ui-refs.c:230) ==8784== by 0x41134D: cgit_print_refs (ui-refs.c:250) ==8784== by 0x407C85: refs_fn (cmd.c:105) ==8784== by 0x405DDF: process_request (cgit.c:566) ==8784== by 0x407490: cache_process (cache.c:322) ==8784== by 0x406C18: main (cgit.c:864) Signed-off-by: Lukas Fleischer --- ui-refs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index 4a9b8d3..e89f836 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -103,6 +103,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) const struct cgit_snapshot_format* f; char *filename; const char *basename; + int free_ref = 0; if (!ref || strlen(ref) < 2) return; @@ -111,8 +112,10 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) if (prefixcmp(ref, basename) != 0) { if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) ref++; - if (isdigit(ref[0])) + if (isdigit(ref[0])) { ref = xstrdup(fmt("%s-%s", basename, ref)); + free_ref = 1; + } } for (f = cgit_snapshot_formats; f->suffix; f++) { @@ -122,6 +125,9 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); html("  "); } + + if (free_ref) + free((char *)ref); } static int print_tag(struct refinfo *ref) { -- cgit v1.2.3-70-g09d2