summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2024-09-29 17:40:03 +0000
committerTom Lane2024-09-29 17:40:03 +0000
commite9339782a631eeef01281bc7e1633dd6b970106e (patch)
treea4522f43ed2d142d22c049bb705849d76d8d3714
parentc1ff2d8bc5be55e302731a16aaff563b7f03ed7c (diff)
In passwordFromFile, don't leak the open file after stat failures.
Oversight in e882bcae0. Per Coverity.
-rw-r--r--src/interfaces/libpq/fe-connect.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index d5a72587d2..4094bcbcf0 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -7482,13 +7482,17 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
#ifndef WIN32
if (fstat(fileno(fp), &stat_buf) != 0)
+ {
+ fclose(fp);
return NULL;
+ }
if (!S_ISREG(stat_buf.st_mode))
{
fprintf(stderr,
libpq_gettext("WARNING: password file \"%s\" is not a plain file\n"),
pgpassfile);
+ fclose(fp);
return NULL;
}
@@ -7498,6 +7502,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
fprintf(stderr,
libpq_gettext("WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
pgpassfile);
+ fclose(fp);
return NULL;
}
#else