<pre style='margin:0'>
Ken (kencu) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/3c9d3c2fc4efb9d1e58e9fb9d44899463391a276">https://github.com/macports/macports-legacy-support/commit/3c9d3c2fc4efb9d1e58e9fb9d44899463391a276</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 3c9d3c2 fix fd leaks in fdopendir
</span>3c9d3c2 is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 3c9d3c2fc4efb9d1e58e9fb9d44899463391a276
</span>Author: kzc <kzc@users.noreply.github.com>
AuthorDate: Thu Aug 27 11:48:42 2020 -0400
<span style='display:block; white-space:pre;color:#404040;'> fix fd leaks in fdopendir
</span>---
src/fdopendir.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/fdopendir.c b/src/fdopendir.c
</span><span style='display:block; white-space:pre;color:#808080;'>index ebabae0..86936be 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -30,6 +30,13 @@ int best_fchdir(int dirfd);
</span>
#define PROTECT_ERRNO(what) ({ int __err = (errno); what; errno = __err; })
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Implementation behavior largely follows these man page descriptions:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * https://www.freebsd.org/cgi/man.cgi?query=fdopendir&sektion=3
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * https://linux.die.net/man/3/fdopendir
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> DIR *fdopendir(int dirfd) {
DIR *dir;
struct stat st;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -43,8 +50,12 @@ DIR *fdopendir(int dirfd) {
</span> return 0;
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if (dirfd == AT_FDCWD)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return opendir (".");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dirfd == AT_FDCWD) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dir = opendir (".");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* dirfd can be closed only upon success */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dir) PROTECT_ERRNO(close(dirfd));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return dir;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
oldCWD = open(".", O_RDONLY);
if (oldCWD == -1)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -58,6 +69,7 @@ DIR *fdopendir(int dirfd) {
</span> dir = opendir (".");
if (best_fchdir(oldCWD) < 0) {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dir) PROTECT_ERRNO(closedir(dir));
</span> if (oldCWD != -1) PROTECT_ERRNO(close(oldCWD));
return 0;
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -65,6 +77,9 @@ DIR *fdopendir(int dirfd) {
</span> if (oldCWD != -1)
PROTECT_ERRNO(close(oldCWD));
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* dirfd can be closed only upon success */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dir && dirfd != -1) PROTECT_ERRNO(close(dirfd));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> return dir;
}
</pre><pre style='margin:0'>
</pre>