output/jack: use AtScopeExit()

This commit is contained in:
Max Kellermann 2016-11-08 15:10:38 +01:00
parent dd9ab16d67
commit cadd186f1b

View File

@ -22,6 +22,7 @@
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "../Wrapper.hxx" #include "../Wrapper.hxx"
#include "config/ConfigError.hxx" #include "config/ConfigError.hxx"
#include "util/ScopeExit.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -557,6 +558,8 @@ JackOutput::Start(Error &error)
jports = nullptr; jports = nullptr;
} }
AtScopeExit(jports) { free(jports); };
assert(num_dports > 0); assert(num_dports > 0);
const char *duplicate_port = nullptr; const char *duplicate_port = nullptr;
@ -584,10 +587,6 @@ JackOutput::Start(Error &error)
if (ret != 0) { if (ret != 0) {
error.Format(jack_output_domain, error.Format(jack_output_domain,
"Not a valid JACK port: %s", dports[i]); "Not a valid JACK port: %s", dports[i]);
if (jports != nullptr)
free(jports);
Stop(); Stop();
return false; return false;
} }
@ -604,18 +603,11 @@ JackOutput::Start(Error &error)
error.Format(jack_output_domain, error.Format(jack_output_domain,
"Not a valid JACK port: %s", "Not a valid JACK port: %s",
duplicate_port); duplicate_port);
if (jports != nullptr)
free(jports);
Stop(); Stop();
return false; return false;
} }
} }
if (jports != nullptr)
free(jports);
return true; return true;
} }