Thread (3 messages) flat view 3 messages, 2 authors, 2016-06-15
STALE3719d

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

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:53:39
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Matthieu Moy <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help