commit 9f4051b55882bee47b3e9667d0d4d6414628827e
parent 3b3e5efe15cfcccbd9da6eba12788bab9623a40f
Author: Johannes Lorenz <[email protected]>
Date: Sun, 24 Jan 2021 19:30:54 +0100
Fix memory leaks (main.cpp, plugin, rtosc)
Diffstat:
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp
@@ -2448,12 +2448,26 @@ const SYNTH_T &MiddleWare::getSynth(void) const
return impl->synth;
}
-const char* MiddleWare::getServerAddress(void) const
+char* MiddleWare::getServerAddress(void) const
{
if(impl->server)
return lo_server_get_url(impl->server);
else
- return "NULL";
+ return nullptr;
+}
+
+char* MiddleWare::getServerPort(void) const
+{
+ char* addr = getServerAddress();
+ char* result;
+ if(addr)
+ {
+ result = lo_url_get_port(addr);
+ free(addr);
+ }
+ else
+ result = nullptr;
+ return result;
}
const PresetsStore& MiddleWare::getPresetsStore() const
diff --git a/src/Misc/MiddleWare.h b/src/Misc/MiddleWare.h
@@ -82,7 +82,8 @@ class MiddleWare
//View Synthesis Parameters
const SYNTH_T &getSynth(void) const;
//liblo stuff
- const char* getServerAddress(void) const;
+ char* getServerAddress(void) const;
+ char* getServerPort(void) const;
const PresetsStore& getPresetsStore() const;
PresetsStore& getPresetsStore();
diff --git a/src/Plugin/ZynAddSubFX/ZynAddSubFX.cpp b/src/Plugin/ZynAddSubFX/ZynAddSubFX.cpp
@@ -514,10 +514,10 @@ private:
middleware->setIdleCallback(__idleCallback, this);
_masterChangedCallback(middleware->spawnMaster());
- if (char* url = lo_url_get_port(middleware->getServerAddress()))
+ if (char* portStr = middleware->getServerPort())
{
- oscPort = std::atoi(url);
- std::free(url);
+ oscPort = std::atoi(portStr);
+ std::free(portStr);
}
else
{
diff --git a/src/main.cpp b/src/main.cpp
@@ -708,7 +708,7 @@ int main(int argc, char *argv[])
#endif
if(!noui) {
printf("[INFO] Launching Zyn-Fusion...\n");
- const char *addr = middleware->getServerAddress();
+ char *addr = middleware->getServerAddress();
#ifndef WIN32
gui_pid = fork();
if(gui_pid == 0) {
@@ -759,6 +759,7 @@ int main(int argc, char *argv[])
exit(1);
}
#endif
+ free(addr);
}
#endif