decoder/wavpack: use AtScopeExit() for exception-safety
This commit is contained in:
parent
8092e18158
commit
fe9bafa741
@ -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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavpack_decode(decoder, wpc, can_seek);
|
AtScopeExit(wpc) {
|
||||||
|
|
||||||
WavpackCloseFile(wpc);
|
WavpackCloseFile(wpc);
|
||||||
|
};
|
||||||
|
|
||||||
if (wvc != nullptr) {
|
wavpack_decode(decoder, wpc, can_seek);
|
||||||
delete &wvc->is;
|
|
||||||
delete wvc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user