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

Lines changed: 12 additions & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy