Content-Length: 285599 | pFad | http://github.com/postgrespro/postgres/commit/d7d294f5935e157f239b32c6d1f3d4e923a4eed5

7A Improve pg_check_dir's handling of closedir() failures. · postgrespro/postgres@d7d294f · GitHub
Skip to content

Commit d7d294f

Browse files
committed
Improve pg_check_dir's handling of closedir() failures.
Avoid losing errno if readdir() fails and closedir() works. This also avoids leaking the directory handle when readdir() fails. Commit 6f03927 introduced logic to better handle readdir() and closedir() failures, bu it missed these cases. Extracted from a larger patch by Marco Nenciarini.
1 parent 2df854f commit d7d294f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/port/pgcheckdir.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pg_check_dir(const char *dir)
3131
int result = 1;
3232
DIR *chkdir;
3333
struct dirent *file;
34+
int readdir_errno;
3435

3536
chkdir = opendir(dir);
3637

@@ -58,8 +59,15 @@ pg_check_dir(const char *dir)
5859
errno = 0;
5960
#endif
6061

61-
if (errno || closedir(chkdir))
62+
if (errno)
6263
result = -1; /* some kind of I/O error? */
6364

65+
/* Close chkdir and avoid overwriting the readdir errno on success */
66+
readdir_errno = errno;
67+
if (closedir(chkdir))
68+
result = -1; /* error executing closedir */
69+
else
70+
errno = readdir_errno;
71+
6472
return result;
6573
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/d7d294f5935e157f239b32c6d1f3d4e923a4eed5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy