diff options
author | Robert Haas <rhaas@postgresql.org> | 2010-10-26 19:28:18 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2010-10-26 19:35:33 -0400 |
commit | 1fea0c05eb4ac4a21d79471b9a7fe96163306b88 (patch) | |
tree | 1fd8610584af7d2d8b3e3c0ccc230a3c6e23cffd /src | |
parent | 5c38782cc8b3219d43ac2ccaf4254fd590bde758 (diff) | |
download | postgresql-1fea0c05eb4ac4a21d79471b9a7fe96163306b88.tar.gz postgresql-1fea0c05eb4ac4a21d79471b9a7fe96163306b88.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/command.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index e6d703abe74..fe37be66f2a 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1987,7 +1987,10 @@ process_file(char *filename, bool single_txn) if ((res = PSQLexec("BEGIN", false)) == NULL) { if (pset.on_error_stop) - return EXIT_USER; + { + result = EXIT_USER; + goto error; + } } else PQclear(res); @@ -2000,13 +2003,19 @@ process_file(char *filename, bool single_txn) if ((res = PSQLexec("COMMIT", false)) == NULL) { if (pset.on_error_stop) - return EXIT_USER; + { + result = EXIT_USER; + goto error; + } } else PQclear(res); } - fclose(fd); +error: + if (fd != stdin) + fclose(fd); + pset.inputfile = oldfilename; return result; } |