aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 15:25:29 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 15:25:29 +0100
commit8e0575ca9b0a711350dfebd71bfae9c000a7f7f9 (patch)
tree8d9866a2e23193ebcc9eaa99f8fa45473909637b /src
parent5e8f51a9632e63656b7e68e90412374b8508fa30 (diff)
downloadmpd-8e0575ca9b0a711350dfebd71bfae9c000a7f7f9.tar.gz
mpd-8e0575ca9b0a711350dfebd71bfae9c000a7f7f9.tar.xz
mpd-8e0575ca9b0a711350dfebd71bfae9c000a7f7f9.zip
archive/zzip: fix memory leak
Diffstat (limited to 'src')
-rw-r--r--src/archive/ZzipArchivePlugin.cxx27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx
index ba001bdd5..38cb4e92c 100644
--- a/src/archive/ZzipArchivePlugin.cxx
+++ b/src/archive/ZzipArchivePlugin.cxx
@@ -39,18 +39,18 @@ class ZzipArchiveFile : public ArchiveFile {
public:
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() {
- if (!ref.Decrement())
- return;
-
- //close archive
- zzip_dir_close (dir);
+ ~ZzipArchiveFile() {
+ zzip_dir_close(dir);
+ }
- delete this;
+ void Unref() {
+ if (ref.Decrement())
+ delete this;
}
void Visit(ArchiveVisitor &visitor);
@@ -69,17 +69,14 @@ zzip_quark(void)
static ArchiveFile *
zzip_archive_open(const char *pathname, GError **error_r)
{
- ZzipArchiveFile *context = new ZzipArchiveFile();
-
- // open archive
- context->dir = zzip_dir_open(pathname, NULL);
- if (context->dir == NULL) {
+ ZZIP_DIR *dir = zzip_dir_open(pathname, NULL);
+ if (dir == nullptr) {
g_set_error(error_r, zzip_quark(), 0,
"Failed to open ZIP file %s", pathname);
return NULL;
}
- return context;
+ return new ZzipArchiveFile(dir);
}
inline void