summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-21 13:49:34 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-21 13:49:34 +0100
commitbb4690f1f1ddd40ff9e987ff94151e1e1efbdde0 (patch)
tree6e817c5a0df2d72a62e8d628dd5301d9a9d6cede /signal-composer-binding
parentd846a71ed3704b55f3eb29ff83777699916beb5f (diff)
Don't segfault at exit pointed to freed objects
Change-Id: Ic2f8ebee552ce982f858fe6ee93db2508a290617 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer.cpp9
-rw-r--r--signal-composer-binding/signal.cpp5
2 files changed, 8 insertions, 6 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index fa565cb..9fc7109 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -89,9 +89,11 @@ Composer::Composer()
Composer::~Composer()
{
+ // This will free onReceived_ action member from signal objects
+ // Not the best to have it occurs here instead of in Signal destructor
for(auto& j: ctlActionsJ_)
{
- json_object_put(j);
+ if(j) json_object_put(j);
}
if (ctlConfig_->configJ) json_object_put(ctlConfig_->configJ);
if (ctlConfig_->requireJ)json_object_put(ctlConfig_->requireJ);
@@ -543,8 +545,9 @@ void Composer::processOptions(const std::map<std::string, int>& opts, std::share
Composer& Composer::instance()
{
- static Composer composer;
- return composer;
+ static Composer* composer;
+ if(!composer) composer = new Composer();
+ return *composer;
}
void* Composer::createContext(void* ctx)
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index dcbf814..84be8a7 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -75,9 +75,8 @@ Signal::Signal(const std::string& id,
Signal::~Signal()
{
- json_object_put(onReceived_->argsJ);
- json_object_put(getSignalsArgs_);
- delete(onReceived_);
+ if(getSignalsArgs_) json_object_put(getSignalsArgs_);
+ if(onReceived_) delete(onReceived_);
}
Signal::operator bool() const