aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 15:27:23 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 15:27:23 +0100
commit701fff03d27be629f416534744217eadbde11da4 (patch)
tree2678c4d88ac38c7390c7f0d2e255cb47a9898d8e
parent8e0575ca9b0a711350dfebd71bfae9c000a7f7f9 (diff)
downloadmpd-701fff03d27be629f416534744217eadbde11da4.tar.gz
mpd-701fff03d27be629f416534744217eadbde11da4.tar.xz
mpd-701fff03d27be629f416534744217eadbde11da4.zip
archive/bzip2: create file only after stream has been opened
Simplify error handling.
-rw-r--r--src/archive/Bzip2ArchivePlugin.cxx43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx
index daa04b975..d9bbe94ad 100644
--- a/src/archive/Bzip2ArchivePlugin.cxx
+++ b/src/archive/Bzip2ArchivePlugin.cxx
@@ -46,18 +46,28 @@ class Bzip2ArchiveFile : public ArchiveFile {
public:
RefCount ref;
- char *name;
- struct input_stream *istream;
+ char *const name;
+ struct input_stream *const istream;
+
+ Bzip2ArchiveFile(const char *path, input_stream *_is)
+ :ArchiveFile(bz2_archive_plugin),
+ name(g_path_get_basename(path)),
+ istream(_is) {
+ // remove .bz2 suffix
+ size_t len = strlen(name);
+ if (len > 4)
+ name[len - 4] = 0;
+ }
- Bzip2ArchiveFile():ArchiveFile(bz2_archive_plugin) {}
+ ~Bzip2ArchiveFile() {
+ input_stream_close(istream);
+ }
void Unref() {
if (!ref.Decrement())
return;
g_free(name);
-
- input_stream_close(istream);
delete this;
}
};
@@ -123,28 +133,13 @@ Bzip2InputStream::Close()
static ArchiveFile *
bz2_open(const char *pathname, GError **error_r)
{
- Bzip2ArchiveFile *context = new Bzip2ArchiveFile();
- int len;
-
- //open archive
static Mutex mutex;
static Cond cond;
- context->istream = input_stream_open(pathname, mutex, cond,
- error_r);
- if (context->istream == NULL) {
- delete context;
- return NULL;
- }
-
- context->name = g_path_get_basename(pathname);
-
- //remove suffix
- len = strlen(context->name);
- if (len > 4) {
- context->name[len - 4] = 0; //remove .bz2 suffix
- }
+ input_stream *is = input_stream_open(pathname, mutex, cond, error_r);
+ if (is == nullptr)
+ return nullptr;
- return context;
+ return new Bzip2ArchiveFile(pathname, is);
}
static void