List for cgit developers and users
 help / color / mirror / Atom feed
From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH 2/6] print_tag_downloads(): Free ref variable
Date: Mon,  4 Mar 2013 13:25:34 +0100	[thread overview]
Message-ID: <1362399938-20209-3-git-send-email-cgit@cryptocrack.de> (raw)
In-Reply-To: <1362399938-20209-1-git-send-email-cgit@cryptocrack.de>

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 at cryptocrack.de>
---
 ui-refs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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("&nbsp;&nbsp;");
 	}
+
+	if (free_ref)
+		free((char *)ref);
 }
 static int print_tag(struct refinfo *ref)
 {
-- 
1.8.2.rc0.247.g811e0c0





  parent reply	other threads:[~2013-03-04 12:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-04 12:25 [PATCH 0/6] Fix several obvious memory leaks cgit
2013-03-04 12:25 ` [PATCH 1/6] Free reflists after usage cgit
2013-03-04 12:25 ` cgit [this message]
2013-03-04 12:25 ` [PATCH 3/6] find_default_branch(): Free refmatch " cgit
2013-03-04 12:25 ` [PATCH 4/6] cgit_print_tree(): Free curr_rev " cgit
2013-03-05  1:36   ` Jason
2013-03-04 12:25 ` [PATCH 5/6] cgit_print_commit(): Free tmp variable cgit
2013-03-04 12:25 ` [PATCH 6/6] cgit_print_snapshot_links(): Free prefix variable cgit
2013-03-05  0:53 ` [PATCH 0/6] Fix several obvious memory leaks Jason
2013-03-05  1:50   ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362399938-20209-3-git-send-email-cgit@cryptocrack.de \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).