Commit fe9bafa7 authored by Max Kellermann's avatar Max Kellermann

decoder/wavpack: use AtScopeExit() for exception-safety

parent 8092e181
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/Macros.hxx" #include "util/Macros.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/ScopeExit.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <wavpack/wavpack.h> #include <wavpack/wavpack.h>
...@@ -485,10 +486,11 @@ wavpack_open_wvc(Decoder &decoder, const char *uri) ...@@ -485,10 +486,11 @@ wavpack_open_wvc(Decoder &decoder, const char *uri)
return nullptr; return nullptr;
char *wvc_url = xstrcatdup(uri, "c"); char *wvc_url = xstrcatdup(uri, "c");
AtScopeExit(wvc_url) {
free(wvc_url);
};
auto is_wvc = decoder_open_uri(decoder, uri, IgnoreError()); auto is_wvc = decoder_open_uri(decoder, uri, IgnoreError());
free(wvc_url);
if (is_wvc == nullptr) if (is_wvc == nullptr)
return nullptr; return nullptr;
...@@ -510,6 +512,13 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is) ...@@ -510,6 +512,13 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
can_seek &= wvc->is.IsSeekable(); can_seek &= wvc->is.IsSeekable();
} }
AtScopeExit(wvc) {
if (wvc != nullptr) {
delete &wvc->is;
delete wvc;
}
};
if (!can_seek) { if (!can_seek) {
open_flags |= OPEN_STREAMING; open_flags |= OPEN_STREAMING;
} }
...@@ -527,14 +536,11 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is) ...@@ -527,14 +536,11 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
return; return;
} }
wavpack_decode(decoder, wpc, can_seek); AtScopeExit(wpc) {
WavpackCloseFile(wpc);
};
WavpackCloseFile(wpc); wavpack_decode(decoder, wpc, can_seek);
if (wvc != nullptr) {
delete &wvc->is;
delete wvc;
}
} }
/* /*
......
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