input/archive: use AtScopeExit() for exception-safety
This commit is contained in:
parent
3143dbf3dc
commit
90c8a1b1cf
@ -27,6 +27,7 @@
|
|||||||
#include "../InputPlugin.hxx"
|
#include "../InputPlugin.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
#include "util/ScopeExit.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -34,15 +35,17 @@ InputStream *
|
|||||||
OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond, Error &error)
|
OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond, Error &error)
|
||||||
{
|
{
|
||||||
const ArchivePlugin *arplug;
|
const ArchivePlugin *arplug;
|
||||||
InputStream *is;
|
|
||||||
|
|
||||||
char *pname = strdup(path.c_str());
|
char *pname = strdup(path.c_str());
|
||||||
|
AtScopeExit(pname) {
|
||||||
|
free(pname);
|
||||||
|
};
|
||||||
|
|
||||||
// archive_lookup will modify pname when true is returned
|
// archive_lookup will modify pname when true is returned
|
||||||
const char *archive, *filename, *suffix;
|
const char *archive, *filename, *suffix;
|
||||||
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
|
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
|
||||||
FormatDebug(archive_domain,
|
FormatDebug(archive_domain,
|
||||||
"not an archive, lookup %s failed", pname);
|
"not an archive, lookup %s failed", pname);
|
||||||
free(pname);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,22 +54,19 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond, Error &error)
|
|||||||
if (!arplug) {
|
if (!arplug) {
|
||||||
FormatWarning(archive_domain,
|
FormatWarning(archive_domain,
|
||||||
"can't handle archive %s", archive);
|
"can't handle archive %s", archive);
|
||||||
free(pname);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file = archive_file_open(arplug, Path::FromFS(archive), error);
|
auto file = archive_file_open(arplug, Path::FromFS(archive), error);
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
free(pname);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//setup fileops
|
AtScopeExit(file) {
|
||||||
is = file->OpenStream(filename, mutex, cond, error);
|
|
||||||
free(pname);
|
|
||||||
file->Close();
|
file->Close();
|
||||||
|
};
|
||||||
|
|
||||||
return is;
|
return file->OpenStream(filename, mutex, cond, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static InputStream *
|
static InputStream *
|
||||||
|
Loading…
Reference in New Issue
Block a user