git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC memory leak?] Minor memory leak fix
@ 2014-03-11 10:45 Fredrik Gustafsson
  2014-03-11 11:58 ` Duy Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: Fredrik Gustafsson @ 2014-03-11 10:45 UTC (permalink / raw)
  To: git; +Cc: iveqy

Strbuf needs to be released even if it's locally declared.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
 archive.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/archive.c b/archive.c
index 346f3b2..d6d56e6 100644
--- a/archive.c
+++ b/archive.c
@@ -113,6 +113,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 	struct git_attr_check check[2];
 	const char *path_without_prefix;
 	int err;
+	int to_ret = 0;
 
 	args->convert = 0;
 	strbuf_reset(&path);
@@ -126,8 +127,10 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 
 	setup_archive_check(check);
 	if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) {
-		if (ATTR_TRUE(check[0].value))
-			return 0;
+		if (ATTR_TRUE(check[0].value)) {
+			to_ret = 0;
+			goto cleanup;
+		}
 		args->convert = ATTR_TRUE(check[1].value);
 	}
 
@@ -135,14 +138,20 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 		if (args->verbose)
 			fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
 		err = write_entry(args, sha1, path.buf, path.len, mode);
-		if (err)
-			return err;
-		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
+		if (err) {
+			to_ret = err;
+			goto cleanup;
+		}
+		to_ret = (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
+		goto cleanup;
 	}
 
 	if (args->verbose)
 		fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
-	return write_entry(args, sha1, path.buf, path.len, mode);
+	to_ret = write_entry(args, sha1, path.buf, path.len, mode);
+cleanup:
+	strbuf_release(&path);
+	return to_ret;
 }
 
 int write_archive_entries(struct archiver_args *args,
-- 
1.8.3.1.490.g39d9b24.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-11 19:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-11 10:45 [RFC memory leak?] Minor memory leak fix Fredrik Gustafsson
2014-03-11 11:58 ` Duy Nguyen
2014-03-11 12:36   ` [[RFC memory leak, v.2]] " Fredrik Gustafsson
2014-03-11 19:40     ` René Scharfe
2014-03-11 12:40   ` [RFC memory leak?] " Fredrik Gustafsson
2014-03-11 19:42     ` Junio C Hamano

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).