Fix memory leak found by Coverity in pg_regress
Not sure if the prehook functionality is used but let's fix the leak
anyway.
@@ -2916,22 +2916,16 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
if (prehook[0])
{
- char *fullname = malloc(strlen(inputdir) +
- strlen("/sql/hooks/") +
- strlen(prehook) +
- strlen(".sql") +
- 1 /* '\0' */);
- sprintf(fullname, "%s/sql/hooks/%s.sql", inputdir, prehook);
- prehook = fullname;
+ char *fullname = psprintf("%s/sql/hooks/%s.sql", inputdir, prehook);
- if (!file_exists(prehook))
+ if (!file_exists(fullname))
{
convert_sourcefiles_in("input/hooks", outputdir, "sql/hooks", "sql");
- if (!file_exists(prehook))
+ if (!file_exists(fullname))
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
- progname, prehook, strerror(errno));
+ progname, fullname, strerror(errno));
exit(2);
}
}
