diff --git a/src/input/plugins/ArchiveInputPlugin.cxx b/src/input/plugins/ArchiveInputPlugin.cxx index 8d83fa3f4..590155d0e 100644 --- a/src/input/plugins/ArchiveInputPlugin.cxx +++ b/src/input/plugins/ArchiveInputPlugin.cxx @@ -27,6 +27,7 @@ #include "../InputPlugin.hxx" #include "fs/Path.hxx" #include "Log.hxx" +#include "util/ScopeExit.hxx" #include @@ -34,15 +35,17 @@ InputStream * OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond, Error &error) { const ArchivePlugin *arplug; - InputStream *is; char *pname = strdup(path.c_str()); + AtScopeExit(pname) { + free(pname); + }; + // archive_lookup will modify pname when true is returned const char *archive, *filename, *suffix; if (!archive_lookup(pname, &archive, &filename, &suffix)) { FormatDebug(archive_domain, "not an archive, lookup %s failed", pname); - free(pname); return nullptr; } @@ -51,22 +54,19 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond, Error &error) if (!arplug) { FormatWarning(archive_domain, "can't handle archive %s", archive); - free(pname); return nullptr; } auto file = archive_file_open(arplug, Path::FromFS(archive), error); if (file == nullptr) { - free(pname); return nullptr; } - //setup fileops - is = file->OpenStream(filename, mutex, cond, error); - free(pname); - file->Close(); + AtScopeExit(file) { + file->Close(); + }; - return is; + return file->OpenStream(filename, mutex, cond, error); } static InputStream *