Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fea0c0

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

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-
returnEXIT_USER;
1990+
{
1991+
result=EXIT_USER;
1992+
gotoerror;
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-
returnEXIT_USER;
2006+
{
2007+
result=EXIT_USER;
2008+
gotoerror;
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
returnresult;
20122021
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp