Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1fea0c0

Browse files
committed
Minor fixups for psql's process_file() function.
- Avoid closing stdin, since we didn't open it. Previously multiple inclusions of stdin would be terminated with a single quit, now a separate quit is needed for each invocation. Previous behavior also accessed stdin after it was fclose()d, which is undefined behavior per ANSI C. - Properly restore pset.inputfile, since the caller expects to be able to free that memory. Marti Raudsepp
1 parent 5c38782 commit 1fea0c0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/bin/psql/command.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,10 @@ process_file(char *filename, bool single_txn)
19871987
if ((res = PSQLexec("BEGIN", false)) == NULL)
19881988
{
19891989
if (pset.on_error_stop)
1990-
return EXIT_USER;
1990+
{
1991+
result = EXIT_USER;
1992+
goto error;
1993+
}
19911994
}
19921995
else
19931996
PQclear(res);
@@ -2000,13 +2003,19 @@ process_file(char *filename, bool single_txn)
20002003
if ((res = PSQLexec("COMMIT", false)) == NULL)
20012004
{
20022005
if (pset.on_error_stop)
2003-
return EXIT_USER;
2006+
{
2007+
result = EXIT_USER;
2008+
goto error;
2009+
}
20042010
}
20052011
else
20062012
PQclear(res);
20072013
}
20082014

2009-
fclose(fd);
2015+
error:
2016+
if (fd != stdin)
2017+
fclose(fd);
2018+
20102019
pset.inputfile = oldfilename;
20112020
return result;
20122021
}

0 commit comments

Comments
 (0)