Skip to content

Commit 0b9076c

Browse files
committed
fix: prevent fd leak in TraversalType2 implementation
1 parent f8f106b commit 0b9076c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libappimage/core/impl/TraversalType2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
extern "C" {
99
#include <squashfuse.h>
1010
#include <squashfs_fs.h>
11+
#include <squashfuse/util.h>
1112
}
1213

1314
// system
@@ -52,15 +53,25 @@ class TraversalType2::Priv {
5253
rootInodeId = sqfs_inode_root(&fs);
5354
err = sqfs_traverse_open(&trv, &fs, rootInodeId);
5455
if (err != SQFS_OK) {
56+
// Save the file descriptor before destroying the fs structure
57+
sqfs_fd_t fd = fs.fd;
5558
sqfs_destroy(&fs);
59+
// Close the file descriptor to prevent fd leak
60+
sqfs_fd_close(fd);
5661
throw IOError("sqfs_traverse_open error");
5762
}
5863
}
5964

6065
virtual ~Priv() {
6166
sqfs_traverse_close(&trv);
6267

68+
// Save the file descriptor before destroying the fs structure
69+
sqfs_fd_t fd = fs.fd;
70+
6371
sqfs_destroy(&fs);
72+
73+
// Close the file descriptor to prevent fd leak
74+
sqfs_fd_close(fd);
6475
}
6576

6677
bool isCompleted() const {

0 commit comments

Comments
 (0)