git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] config: allow ~/ and ~user/ in include.path value

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Apr 24, 2012, 18:33 UTC
Message-ID
<1335292396-8502-1-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1335265689-2270-1-git-send-email-Matthieu.Moy@imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
Just added a free(path) before must_free_path = 0. Not that the memory
leak is really problematic, but let's be clean.
 config.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index bfe0c79..f054a35 100644
--- a/config.c
+++ b/config.c
@@ -33,11 +33,14 @@ static const char include_depth_advice[] =
 "from\n"
 "	%s\n"
 "Do you have circular includes?";
-static int handle_path_include(const char *path, struct config_include_data *inc)
+static int handle_path_include(const char *raw_path, struct config_include_data *inc)
 {
 	int ret = 0;
 	struct strbuf buf = STRBUF_INIT;
-
+	int must_free_path = 1;
+	char *path = expand_user_path(raw_path);
+	if (!path)
+		return error("Could not expand include path '%s'.", raw_path);
 	/*
 	 * Use an absolute path as-is, but interpret relative paths
 	 * based on the including config file.
@@ -52,6 +55,8 @@ static int handle_path_include(const char *path, struct config_include_data *inc
 		if (slash)
 			strbuf_add(&buf, cf->name, slash - cf->name + 1);
 		strbuf_addstr(&buf, path);
+		free(path);
+		must_free_path = 0;
 		path = buf.buf;
 	}
 
@@ -63,6 +68,8 @@ static int handle_path_include(const char *path, struct config_include_data *inc
 		inc->depth--;
 	}
 	strbuf_release(&buf);
+	if (must_free_path)
+		free(path);
 	return ret;
 }
 
-- 
1.7.10.235.gb2edec.dirty
Previous: Matthieu MoyNext: Jeff King
Message 2 of 6 in “config: allow ~/ and ~user/ in include.path value”
  1. config: allow ~/ and ~user/ in include.path valueMatthieu Moy, Apr 24, 2012
  2. config: allow ~/ and ~user/ in include.path valueMatthieu Moy, Apr 24, 2012
  3. Jeff KingApr 25, 2012
  4. Matthieu MoyApr 25, 2012
  5. Junio C HamanoApr 25, 2012
  6. Jeff KingApr 26, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.