Skip to contentSkip to conversation

submodule.c: duplicate real_path's return value

PATCH New Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 submodule.c: duplicate real_path's return value

real_path returns the pointer to an internal buffer, which may be overwritten by the next real_path call. Duplicate the return value for safety.

---
Apply on top of jl/submodule-mv.

Junio, I think this is the reason some tests failed when you merged nd/magic-pathspecs in (I suspect you needed to do parse_pathspec call, which may do real_path internaly).

I think "bug" fix like this should go in early, hence this patch. I'm going to rebase nd/magic-pathspecs after this series graduates to master anyway, feel free to reject.

 submodule.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
submodule.c +3 -1
index 6b01a02..9f442d8 100644
@@ -1102,7 +1102,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	struct strbuf configfile_name = STRBUF_INIT;
 	struct strbuf gitfile_content = STRBUF_INIT;
 	struct strbuf gitfile_name = STRBUF_INIT;
-	const char *real_work_tree = real_path(work_tree);
+	char *real_work_tree = xstrdup(real_path(work_tree));
+	char *to_free = real_work_tree;
 	const char *pathspec[] = { real_work_tree, git_dir, NULL };
 	const char *max_prefix = common_prefix(pathspec);
 	FILE *fp;
@@ -1157,4 +1158,5 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 
 	strbuf_release(&core_worktree_setting);
 	strbuf_release(&configfile_name);
+	free(to_free);
 }
Signature · 1 line
1.8.2.82.gc24b958