Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Valgrind automatic tests, ran for almost every Zsh test and zredis



On Jun 18,  1:18pm, Sebastian Gniazdowski wrote:
}
} Today I wanted to catch something. The bicat() usage seems to leak
} what getoutputfile() returns:
}
} - that function always calls: gettempname(NULL, 0), and the 0 == zalloc()
}   memory
} - in stringsubst(), after memcpy(), result of getoutputfile() is unused,
}   free to release
} 
} Attached is a patch with fix for this, it removes the Valgrind error.

Hmm, looking more carefully at this, the problem actually seems to be that
getoutputfile() doesn't need to pass 0 to gettempname() any longer.  There
used to be a direct call to zaddlinknode() in getoutputfile(), which needed
a zalloc() string, but that was replaced by addfilelist() which does its own
internal ztrdup().

So the fix is a whole lot simpler:

diff --git a/Src/exec.c b/Src/exec.c
index debb0ae..0a96879 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4570,7 +4570,7 @@ getoutputfile(char *cmd, char **eptr)
     }
     if (!(prog = parsecmd(cmd, eptr)))
 	return NULL;
-    if (!(nam = gettempname(NULL, 0)))
+    if (!(nam = gettempname(NULL, 1)))
 	return NULL;
 
     if ((s = simple_redir_name(prog, REDIR_HERESTR))) {
@@ -4601,7 +4601,7 @@ getoutputfile(char *cmd, char **eptr)
 	    suffix = dyncat(nam, unmeta(suffix));
 	    if (link(nam, suffix) == 0) {
 		addfilelist(nam, 0);
-		nam = ztrdup(suffix);
+		nam = suffix;
 	    }
 	}
     }



Messages sorted by: Reverse Date, Date, Thread, Author