From: Jonathan Nieder <jrnieder@gmail•com>
To: Junio C Hamano <gitster@pobox•com>
Cc: git@vger•kernel.org
Subject: [PATCH 6/7] environment: use alloc_permanent() for computed git_dir and co
Date: Sat, 2 Oct 2010 03:39:58 -0500 [thread overview]
Message-ID: <20101002083958.GG29638@burratino> (raw)
In-Reply-To: <20101002082752.GA29638@burratino>
The in-core variables to match $GIT_DIR, $GIT_OBJECT_DIRECTORY, etc
come from three sources:
a) environment variables [getenv("GIT_INDEX_FILE")]
b) computation [git_pathdup("objects")]
c) static strings [".git"]
Only in case (b) are they malloc()'d; even in that case, it
would not make sense to free the values until program termination,
when _exit() takes care of freeing all memory already.
So mark the allocations in case (b) as permanent so no one wastes
time trying to fix the leak.
Signed-off-by: Jonathan Nieder <jrnieder@gmail•com>
---
environment.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/environment.c b/environment.c
index de5581f..9bd18c7 100644
--- a/environment.c
+++ b/environment.c
@@ -89,23 +89,23 @@ static void setup_git_env(void)
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir) {
git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
+ git_dir = git_dir ? strdup_permanent(git_dir) : NULL;
}
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
- git_object_dir = xmalloc(strlen(git_dir) + 9);
+ git_object_dir = alloc_permanent(strlen(git_dir) + 9);
sprintf(git_object_dir, "%s/objects", git_dir);
}
git_index_file = getenv(INDEX_ENVIRONMENT);
if (!git_index_file) {
- git_index_file = xmalloc(strlen(git_dir) + 7);
+ git_index_file = alloc_permanent(strlen(git_dir) + 7);
sprintf(git_index_file, "%s/index", git_dir);
}
git_graft_file = getenv(GRAFT_ENVIRONMENT);
if (!git_graft_file)
- git_graft_file = git_pathdup("info/grafts");
+ git_graft_file = git_pathdup_permanent("info/grafts");
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;
}
--
1.7.2.3
next prev parent reply other threads:[~2010-10-02 8:43 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-09 9:48 [PATCH] memory leak reported by valgrind Ivan Kanis
2010-08-09 19:37 ` Junio C Hamano
2010-08-09 20:19 ` Erik Faye-Lund
2010-08-09 20:29 ` Alex Riesen
2010-08-10 3:26 ` Jonathan Nieder
2010-08-10 3:28 ` [PATCH/RFC 1/3] core: Stop leaking ondisk_cache_entrys Jonathan Nieder
2010-08-10 3:32 ` [PATCH/RFC 2/3] write-tree: Avoid leak when index refers to an invalid object Jonathan Nieder
2010-08-10 3:33 ` [PATCH/RFC 3/3] read-tree: stop leaking tree objects Jonathan Nieder
2010-10-02 8:27 ` [PATCH/RFC 0/7] Re: [PATCH] memory leak reported by valgrind Jonathan Nieder
2010-10-02 8:31 ` [PATCH 1/7] init: plug tiny one-time memory leak Jonathan Nieder
2010-10-03 23:46 ` Junio C Hamano
2010-10-04 4:34 ` [PATCH v2] " Jonathan Nieder
2010-10-02 8:32 ` [PATCH 2/7] lockfile: introduce alloc_lock_file() to avoid valgrind noise Jonathan Nieder
2010-10-02 16:30 ` Andreas Ericsson
2010-10-02 16:43 ` Jonathan Nieder
2010-10-06 20:10 ` Junio C Hamano
2010-10-06 20:21 ` Jonathan Nieder
2010-10-06 21:45 ` Junio C Hamano
2010-10-06 22:17 ` Jonathan Nieder
2010-10-02 8:35 ` [PATCH 3/7] environment.c: remove unused variable Jonathan Nieder
2010-10-02 8:36 ` [PATCH 4/7] setup: make sure git dir path is in a permanent buffer Jonathan Nieder
2010-10-04 9:25 ` Nguyen Thai Ngoc Duy
2010-10-02 8:38 ` [PATCH 5/7] Introduce malloc/strdup/pathdup variants for permanent allocations Jonathan Nieder
2010-10-02 8:39 ` Jonathan Nieder [this message]
2010-10-02 8:41 ` [PATCH 7/7] commit-tree: free commit message before exiting Jonathan Nieder
2010-10-02 18:14 ` Sverre Rabbelier
2010-10-02 18:26 ` Jonathan Nieder
2010-10-02 20:12 ` Sverre Rabbelier
2010-10-02 20:50 ` Jonathan Nieder
2010-10-04 0:31 ` Junio C Hamano
2010-10-04 4:18 ` Jonathan Nieder
2010-10-04 7:55 ` Junio C Hamano
2010-10-04 7:56 ` Jonathan Nieder
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=20101002083958.GG29638@burratino \
--to=jrnieder@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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