diff options
author | Rubidium <rubidium@openttd.org> | 2021-05-09 23:00:36 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-10 16:03:31 +0200 |
commit | 495d73a67fe924eed5504003a3a5ba30758dcbc5 (patch) | |
tree | de9bc17ecb513bedcd00315e0f5b3151d95d2f6a /src/network | |
parent | 296194ad36c601cf12d215a65d84222bbdf4de61 (diff) | |
download | openttd-495d73a67fe924eed5504003a3a5ba30758dcbc5.tar.xz |
Fix: leaking file descriptors
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_content.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 528b7bd77..e4f368618 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -410,7 +410,8 @@ static bool GunzipFile(const ContentInfo *ci) FILE *ftmp = fopen(GetFullFilename(ci, true).c_str(), "rb"); if (ftmp == nullptr) return false; /* Duplicate the handle, and close the FILE*, to avoid double-closing the handle later. */ - gzFile fin = gzdopen(dup(fileno(ftmp)), "rb"); + int fdup = dup(fileno(ftmp)); + gzFile fin = gzdopen(fdup, "rb"); fclose(ftmp); FILE *fout = fopen(GetFullFilename(ci, false).c_str(), "wb"); @@ -449,7 +450,12 @@ static bool GunzipFile(const ContentInfo *ci) } } - if (fin != nullptr) gzclose(fin); + if (fin != nullptr) { + gzclose(fin); + } else if (fdup != -1) { + /* Failing gzdopen does not close the passed file descriptor. */ + close(fdup); + } if (fout != nullptr) fclose(fout); return ret; |