git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benoit Sigoure <tsuna@lrde.epita.fr>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Benoit Sigoure <tsuna@lrde.epita.fr>
Subject: [PATCH] Fix a small memory leak in builtin-add
Date: Mon, 29 Oct 2007 08:00:33 +0100	[thread overview]
Message-ID: <1193641233-3880-2-git-send-email-tsuna@lrde.epita.fr> (raw)
In-Reply-To: <1193641233-3880-1-git-send-email-tsuna@lrde.epita.fr>

prune_directory and fill_directory allocated one byte per pathspec and never
freed it.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
I don't know whether this was intentionnal or not (since it's only a matter of
having small chunks of memory not being reclaimed and I don't think we can
enter these functions twice, so these are not leaks in the sense that the
program will consume more and more memory).  But if it was intentionnal,
wouldn't it be better to put a small comment in the code saying so (so that
casual readers like me won't get surprised).

 builtin-add.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index f9a6580..b8e6094 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -44,6 +44,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 			die("pathspec '%s' did not match any files",
 					pathspec[i]);
 	}
+        free(seen);
 }
 
 static void fill_directory(struct dir_struct *dir, const char **pathspec,
@@ -135,6 +136,7 @@ static void refresh(int verbose, const char **pathspec)
 		if (!seen[i])
 			die("pathspec '%s' did not match any files", pathspec[i]);
 	}
+        free(seen);
 }
 
 static int git_add_config(const char *var, const char *value)
-- 
1.5.3.4.398.g859b

  reply	other threads:[~2007-10-29  7:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-29  7:00 [PATCH] core-tutorial: Catch up with current Git Benoit Sigoure
2007-10-29  7:00 ` Benoit Sigoure [this message]
2007-10-30  8:28   ` [PATCH] Fix a small memory leak in builtin-add Junio C Hamano

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=1193641233-3880-2-git-send-email-tsuna@lrde.epita.fr \
    --to=tsuna@lrde.epita.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).