about summary refs log tree commit diff stats
path: root/ui-refs.c
diff options
context:
space:
mode:
authorLukas Fleischer2013-03-04 13:25:34 +0100
committerJason A. Donenfeld2013-03-04 19:55:21 -0500
commitfab385ef5ca516dcda79df87eb926eccdda64a54 (patch)
tree841673c92d319fac0a7d4b857a88dfcf2c9084e1 /ui-refs.c
parentFree reflists after usage (diff)
downloadcgit-fab385ef5ca516dcda79df87eb926eccdda64a54.tar.gz
cgit-fab385ef5ca516dcda79df87eb926eccdda64a54.zip
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 <cgit@cryptocrack.de>
Diffstat (limited to 'ui-refs.c')
-rw-r--r--ui-refs.c8
1 files changed, 7 insertions, 1 deletions
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)
103 const struct cgit_snapshot_format* f; 103 const struct cgit_snapshot_format* f;
104 char *filename; 104 char *filename;
105 const char *basename; 105 const char *basename;
106 int free_ref = 0;
106 107
107 if (!ref || strlen(ref) < 2) 108 if (!ref || strlen(ref) < 2)
108 return; 109 return;
@@ -111,8 +112,10 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
111 if (prefixcmp(ref, basename) != 0) { 112 if (prefixcmp(ref, basename) != 0) {
112 if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) 113 if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]))
113 ref++; 114 ref++;
114 if (isdigit(ref[0])) 115 if (isdigit(ref[0])) {
115 ref = xstrdup(fmt("%s-%s", basename, ref)); 116 ref = xstrdup(fmt("%s-%s", basename, ref));
117 free_ref = 1;
118 }
116 } 119 }
117 120
118 for (f = cgit_snapshot_formats; f->suffix; f++) { 121 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)
122 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); 125 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
123 html("&nbsp;&nbsp;"); 126 html("&nbsp;&nbsp;");
124 } 127 }
128
129 if (free_ref)
130 free((char *)ref);
125} 131}
126static int print_tag(struct refinfo *ref) 132static int print_tag(struct refinfo *ref)
127{ 133{