mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
@ -1987,7 +1987,10 @@ process_file(char *filename, bool single_txn)
|
|||||||
if ((res = PSQLexec("BEGIN", false)) == NULL)
|
if ((res = PSQLexec("BEGIN", false)) == NULL)
|
||||||
{
|
{
|
||||||
if (pset.on_error_stop)
|
if (pset.on_error_stop)
|
||||||
return EXIT_USER;
|
{
|
||||||
|
result = EXIT_USER;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@ -2000,13 +2003,19 @@ process_file(char *filename, bool single_txn)
|
|||||||
if ((res = PSQLexec("COMMIT", false)) == NULL)
|
if ((res = PSQLexec("COMMIT", false)) == NULL)
|
||||||
{
|
{
|
||||||
if (pset.on_error_stop)
|
if (pset.on_error_stop)
|
||||||
return EXIT_USER;
|
{
|
||||||
|
result = EXIT_USER;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (fd != stdin)
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
||||||
pset.inputfile = oldfilename;
|
pset.inputfile = oldfilename;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user