From e164405c1e92fa895f30ff6a9d2ab02ee898190c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 23 Feb 2024 11:19:59 +0100 Subject: [PATCH] Be explicit that fd are used only a Archive creation. Close opened file descriptor in test before checking equivalence. --- include/zim/archive.h | 6 ++++++ test/archive.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/include/zim/archive.h b/include/zim/archive.h index 80a27cf6b..666e0f931 100644 --- a/include/zim/archive.h +++ b/include/zim/archive.h @@ -97,6 +97,8 @@ namespace zim /** Archive constructor. * * Construct an archive from a file descriptor. + * Fd is used only at Archive creation. + * Ownership of the fd is not taken and it must be closed by caller. * * Note: This function is not available under Windows. * @@ -108,6 +110,8 @@ namespace zim * * Construct an archive from a descriptor of a file with an embedded ZIM * archive inside. + * Fd is used only at Archive creation. + * Ownership of the fd is not taken and it must be closed by caller. * * Note: This function is not available under Windows. * @@ -120,6 +124,8 @@ namespace zim * * Construct an archive from several file descriptors. * Each part may be embedded in a file. + * Fds are used only at Archive creation. + * Ownership of the fds is not taken and they must be closed by caller. * Fds (int) can be the same between FdInput if the parts belong to the same file. * * Note: This function is not available under Windows. diff --git a/test/archive.cpp b/test/archive.cpp index 12108058f..5a1d57d03 100644 --- a/test/archive.cpp +++ b/test/archive.cpp @@ -625,6 +625,7 @@ TEST(ZimArchive, openZIMFileEmbeddedInAnotherFile) const zim::Archive archive1(normalZims[i].path); const int fd = OPEN_READ_ONLY(embeddedZims[i].path); const zim::Archive archive2(zim::FdInput(fd, 8, archive1.getFilesize())); + close(fd); checkEquivalence(archive1, archive2); } @@ -653,6 +654,10 @@ TEST(ZimArchive, openZIMFileMultiPartEmbeddedInAnotherFile) const zim::Archive archive2(fds); + for(auto &fd: fds) { + close(fd.fd); + } + checkEquivalence(archive1, archive2); } }