* [PATCH] update-index: fix xgetcwd() related memory leak
@ 2017-03-30 6:22 Christian Couder
2017-03-30 6:23 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: Christian Couder @ 2017-03-30 6:22 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Nguyen Thai Ngoc Duy,
Ævar Arnfjörð Bjarmason, Jeff King,
Christian Couder
As xgetcwd() returns an allocated buffer, we should free this
buffer when we don't need it any more.
This was found by Coverity.
Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin/update-index.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/builtin/update-index.c b/builtin/update-index.c
index d74d72cc7f..ebfc09faa0 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -125,12 +125,16 @@ static int test_if_untracked_cache_is_supported(void)
struct stat st;
struct stat_data base;
int fd, ret = 0;
+ char *cwd;
strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
if (!mkdtemp(mtime_dir.buf))
die_errno("Could not make temporary directory");
- fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd());
+ cwd = xgetcwd();
+ fprintf(stderr, _("Testing mtime in '%s' "), cwd);
+ free(cwd);
+
atexit(remove_test_directory);
xstat_mtime_dir(&st);
fill_stat_data(&base, &st);
--
2.12.2.510.ge1104a5ee5.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] update-index: fix xgetcwd() related memory leak
2017-03-30 6:22 [PATCH] update-index: fix xgetcwd() related memory leak Christian Couder
@ 2017-03-30 6:23 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2017-03-30 6:23 UTC (permalink / raw)
To: Christian Couder
Cc: git, Junio C Hamano, Nguyen Thai Ngoc Duy,
Ævar Arnfjörð Bjarmason, Christian Couder
On Thu, Mar 30, 2017 at 08:22:08AM +0200, Christian Couder wrote:
> As xgetcwd() returns an allocated buffer, we should free this
> buffer when we don't need it any more.
>
> This was found by Coverity.
>
> Reported-by: Jeff King <peff@peff.net>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
> builtin/update-index.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index d74d72cc7f..ebfc09faa0 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -125,12 +125,16 @@ static int test_if_untracked_cache_is_supported(void)
> struct stat st;
> struct stat_data base;
> int fd, ret = 0;
> + char *cwd;
>
> strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
> if (!mkdtemp(mtime_dir.buf))
> die_errno("Could not make temporary directory");
>
> - fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd());
> + cwd = xgetcwd();
> + fprintf(stderr, _("Testing mtime in '%s' "), cwd);
> + free(cwd);
> +
Yep, this solution looks obviously correct to me.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-30 6:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-30 6:22 [PATCH] update-index: fix xgetcwd() related memory leak Christian Couder
2017-03-30 6:23 ` Jeff King
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).