Commit 8e0575ca authored by Max Kellermann's avatar Max Kellermann

archive/zzip: fix memory leak

parent 5e8f51a9
...@@ -39,17 +39,17 @@ class ZzipArchiveFile : public ArchiveFile { ...@@ -39,17 +39,17 @@ class ZzipArchiveFile : public ArchiveFile {
public: public:
RefCount ref; RefCount ref;
ZZIP_DIR *dir; ZZIP_DIR *const dir;
ZzipArchiveFile():ArchiveFile(zzip_archive_plugin) {} ZzipArchiveFile(ZZIP_DIR *_dir)
:ArchiveFile(zzip_archive_plugin), dir(_dir) {}
void Unref() { ~ZzipArchiveFile() {
if (!ref.Decrement()) zzip_dir_close(dir);
return; }
//close archive
zzip_dir_close (dir);
void Unref() {
if (ref.Decrement())
delete this; delete this;
} }
...@@ -69,17 +69,14 @@ zzip_quark(void) ...@@ -69,17 +69,14 @@ zzip_quark(void)
static ArchiveFile * static ArchiveFile *
zzip_archive_open(const char *pathname, GError **error_r) zzip_archive_open(const char *pathname, GError **error_r)
{ {
ZzipArchiveFile *context = new ZzipArchiveFile(); ZZIP_DIR *dir = zzip_dir_open(pathname, NULL);
if (dir == nullptr) {
// open archive
context->dir = zzip_dir_open(pathname, NULL);
if (context->dir == NULL) {
g_set_error(error_r, zzip_quark(), 0, g_set_error(error_r, zzip_quark(), 0,
"Failed to open ZIP file %s", pathname); "Failed to open ZIP file %s", pathname);
return NULL; return NULL;
} }
return context; return new ZzipArchiveFile(dir);
} }
inline void inline void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment