path: root/path.c
diff options
authorRamsay Jones <>2012-09-04 17:27:54 (GMT)
committerJunio C Hamano <>2012-09-04 20:34:46 (GMT)
commit66a51a9aaec3f53250b1d515a1bd81044ebb354b (patch)
tree72bd0f9b4b4caa15a7fe94e1566d81d440507590 /path.c
parent5b3b8fa2ab188908332358d2c2576491969cd580 (diff)
path.c: Don't discard the return value of vsnpath()
The git_snpath() and git_pathdup() functions both use the (static) function vsnpath() in their implementation. Also, they both discard the return value of vsnpath(), which has the effect of ignoring the side effect of calling cleanup_path() in the non-error return path. In order to ensure that the required cleanup happens, we use the pointer returned by vsnpath(), rather than the buffer passed into vsnpath(), to derive the return value from git_snpath() and git_pathdup(). Signed-off-by: Ramsay Jones <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'path.c')
1 files changed, 6 insertions, 5 deletions
diff --git a/path.c b/path.c
index 9eb5333..741ae77 100644
--- a/path.c
+++ b/path.c
@@ -70,21 +70,22 @@ bad:
char *git_snpath(char *buf, size_t n, const char *fmt, ...)
+ char *ret;
va_list args;
va_start(args, fmt);
- (void)vsnpath(buf, n, fmt, args);
+ ret = vsnpath(buf, n, fmt, args);
- return buf;
+ return ret;
char *git_pathdup(const char *fmt, ...)
- char path[PATH_MAX];
+ char path[PATH_MAX], *ret;
va_list args;
va_start(args, fmt);
- (void)vsnpath(path, sizeof(path), fmt, args);
+ ret = vsnpath(path, sizeof(path), fmt, args);
- return xstrdup(path);
+ return xstrdup(ret);
char *mkpathdup(const char *fmt, ...)