summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Timko <marek.timko@ixonos.com>2013-11-22 12:53:05 +0100
committerMarek Timko <marek.timko@ixonos.com>2013-11-22 13:48:44 +0100
commit97cbb46673d765b72eed4b02d5a6732538c926ca (patch)
tree69ef387d92dc831521ffdbf7387e724c190105de
parent6a455f4687a15470193fc17c8015854c313cef2e (diff)
downloadautomotive-message-broker-97cbb46673d765b72eed4b02d5a6732538c926ca.tar.gz
Memory leaks fixed
^CSignal caught. Exiting gracefully. ==29365== ==29365== HEAP SUMMARY: ==29365== in use at exit: 308,954 bytes in 1,226 blocks ==29365== total heap usage: 321,177 allocs, 319,951 frees, 11,599,206 bytes allocated ==29365== ==29365== LEAK SUMMARY: ==29365== definitely lost: 0 bytes in 0 blocks ==29365== indirectly lost: 0 bytes in 0 blocks ==29365== possibly lost: 133,147 bytes in 328 blocks ==29365== still: reachable: 175,807 bytes in 898 blocks ==29365== suppressed: 0 bytes in 0 blocks ==29365== Reachable blocks (those to which a pointer was found) are not shown. ==29365== To see them, rerun with: --leak-check=full --show-reachable=yes ==29365== ==29365== For counts of detected and suppressed errors, rerun with: -v ==29365== ERROR SUMMARY: 191 errors from 191 contexts (suppressed: 2 from 2) Signed-off-by: Marek Timko <marek.timko@ixonos.com>
-rw-r--r--ambd/glibmainloop.cpp1
-rw-r--r--ambd/pluginloader.cpp32
-rw-r--r--ambd/pluginloader.h14
-rw-r--r--lib/abstractroutingengine.cpp3
-rw-r--r--lib/abstractsink.h1
-rw-r--r--lib/mappropertytype.hpp1
-rw-r--r--lib/vehicleproperty.cpp11
-rw-r--r--lib/vehicleproperty.h5
-rw-r--r--plugins/dbus/abstractdbusinterface.cpp6
-rw-r--r--plugins/dbus/abstractproperty.cpp8
-rw-r--r--plugins/dbus/abstractproperty.h1
-rw-r--r--plugins/dbus/automotivemanager.cpp6
-rw-r--r--plugins/dbus/custompropertyinterface.cpp4
-rw-r--r--plugins/dbus/dbusplugin.cpp15
-rw-r--r--plugins/dbus/dbusplugin.h10
-rw-r--r--plugins/dbus/environmentproperties.h3
-rw-r--r--plugins/dbus/uncategorizedproperty.cpp4
-rw-r--r--plugins/dbus/varianttype.cpp2
-rw-r--r--plugins/gpsd/gpsdplugin.cpp2
19 files changed, 103 insertions, 26 deletions
diff --git a/ambd/glibmainloop.cpp b/ambd/glibmainloop.cpp
index ca8c1940..f2f80ca8 100644
--- a/ambd/glibmainloop.cpp
+++ b/ambd/glibmainloop.cpp
@@ -11,6 +11,7 @@ GlibMainLoop::GlibMainLoop(int argc, char **argv)
GlibMainLoop::~GlibMainLoop()
{
g_main_loop_quit(mainLoop);
+ g_main_loop_unref(mainLoop);
//exit(0);
}
diff --git a/ambd/pluginloader.cpp b/ambd/pluginloader.cpp
index 49357679..7e8e0591 100644
--- a/ambd/pluginloader.cpp
+++ b/ambd/pluginloader.cpp
@@ -53,7 +53,12 @@ std::string get_file_contents(const char *filename)
}
PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int argc, char** argv): f_create(NULL), routingEngine(re), mMainLoop(nullptr)
{
-
+ if(lt_dlinit())
+ {
+ cerr<<"error initializing libtool: "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<lt_dlerror()<<endl;
+ throw std::runtime_error("Error initializing libtool. Aborting");
+ }
+
DebugOut()<<"Loading config file: "<<configFile<<endl;
json_object *rootobject;
json_tokener *tokener = json_tokener_new();
@@ -71,6 +76,7 @@ PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int arg
{
fprintf(stderr, "Error: %s\n", json_tokener_error_desc(err));
// Handle errors, as appropriate for your application.
+ throw std::runtime_error("Invalid config");
}
if (tokener->char_offset < configFile.length()) // XXX shouldn't access internal fields
{
@@ -141,7 +147,7 @@ PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int arg
}
}
- json_object_put(sourcesobject);
+ //json_object_put(sourcesobject);
///read the sinks:
json_object *sinksobject = json_object_object_get(rootobject,"sinks");
@@ -186,13 +192,33 @@ PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int arg
{
throw std::runtime_error("plugin is not a SinkManager");
}
+ else
+ {
+ mSinks.push_back(plugin);
+ }
}
- json_object_put(sinksobject);
+ //json_object_put(sinksobject);
+ json_object_put(rootobject);
+ json_tokener_free(tokener);
}
PluginLoader::~PluginLoader()
{
+ for(auto itr = mSinks.begin(); itr != mSinks.end(); itr++)
+ {
+ delete *itr;
+ }
+
+ for(auto itr = mSources.begin(); itr != mSources.end(); itr++)
+ {
+ delete *itr;
+ }
+
+ auto handle = openHandles.begin();
+ while(handle != openHandles.end())
+ lt_dlclose(*handle++);
+ lt_dlexit();
}
IMainLoop *PluginLoader::mainloop()
diff --git a/ambd/pluginloader.h b/ambd/pluginloader.h
index 5205070a..a902e7b7 100644
--- a/ambd/pluginloader.h
+++ b/ambd/pluginloader.h
@@ -92,15 +92,6 @@ private: ///methods:
{
DebugOut()<<"Loading plugin: "<<pluginName<<endl;
- if(lt_dlinit())
- {
- mErrorString = lt_dlerror();
- cerr<<"error initializing libtool: "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
- return nullptr;
- }
-
- lt_dlerror();
-
lt_dlhandle handle = lt_dlopenext(pluginName.c_str());
if(!handle)
@@ -109,6 +100,7 @@ private: ///methods:
cerr<<"error opening plugin: "<<pluginName<<" in "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<<mErrorString<<endl;
return nullptr;
}
+ openHandles.push_back(handle);
m_create = (create_mainloop_t *)lt_dlsym(handle, "create");
@@ -129,13 +121,15 @@ private:
AbstractRoutingEngine* routingEngine;
SourceList mSources;
- SinkList mSinks;
+ list<AbstractSinkManager*> mSinks;
create_t * f_create;
create_mainloop_t * m_create;
IMainLoop* mMainLoop;
+
+ std::vector<lt_dlhandle> openHandles;
};
#endif // PLUGINLOADER_H
diff --git a/lib/abstractroutingengine.cpp b/lib/abstractroutingengine.cpp
index ce153d00..1b13f41b 100644
--- a/lib/abstractroutingengine.cpp
+++ b/lib/abstractroutingengine.cpp
@@ -35,7 +35,8 @@ AsyncPropertyReply::AsyncPropertyReply(const AsyncSetPropertyRequest &request)
:AsyncPropertyRequest(request), value(request.value), success(false), timeoutSource(nullptr)
{
setTimeout();
- value->zone = request.zoneFilter;
+ if(value)
+ value->zone = request.zoneFilter;
}
void AsyncPropertyReply::setTimeout()
diff --git a/lib/abstractsink.h b/lib/abstractsink.h
index cf9c7de8..749bcc5f 100644
--- a/lib/abstractsink.h
+++ b/lib/abstractsink.h
@@ -78,6 +78,7 @@ class AbstractSinkManager
public:
AbstractSinkManager(AbstractRoutingEngine* engine, map<string, string> config);
+ virtual ~AbstractSinkManager(){}
protected:
AbstractRoutingEngine* routingEngine;
diff --git a/lib/mappropertytype.hpp b/lib/mappropertytype.hpp
index 694400bf..dff99925 100644
--- a/lib/mappropertytype.hpp
+++ b/lib/mappropertytype.hpp
@@ -83,6 +83,7 @@ public:
}
json_object_put(rootobject);
+ json_tokener_free(tokener);
}
diff --git a/lib/vehicleproperty.cpp b/lib/vehicleproperty.cpp
index 0fc9a5c4..8b7f3626 100644
--- a/lib/vehicleproperty.cpp
+++ b/lib/vehicleproperty.cpp
@@ -288,6 +288,17 @@ void VehicleProperty::factory()
thereCanOnlyBeOne = new VehicleProperty();
}
+void VehicleProperty::shutdown()
+{
+ if(thereCanOnlyBeOne){
+ delete thereCanOnlyBeOne;
+ thereCanOnlyBeOne = nullptr;
+ }
+ registeredPropertyFactoryMap.clear();
+ mCapabilities.clear();
+ mCustomProperties.clear();
+}
+
std::list<VehicleProperty::Property> VehicleProperty::capabilities()
{
return mCapabilities;
diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h
index 2bea435b..86b5ff83 100644
--- a/lib/vehicleproperty.h
+++ b/lib/vehicleproperty.h
@@ -274,6 +274,11 @@ public:
* \brief factory constructs a static instance of VehicleProperty. This should be called once before VehicleProperty is used in the app
*/
static void factory();
+ /*!
+ *
+ * \brief destroys static instance of VehicleProperty. This should be called at application shutdown
+ */
+ static void shutdown();
typedef std::string Property;
diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp
index 0da66286..c2dbb087 100644
--- a/plugins/dbus/abstractdbusinterface.cpp
+++ b/plugins/dbus/abstractdbusinterface.cpp
@@ -207,7 +207,8 @@ AbstractDBusInterface::~AbstractDBusInterface()
{
if(properties.find(*itr) != properties.end())
{
- delete properties[*itr];
+ // Deleted in ~DBusSink()
+ //delete properties[*itr];
properties.erase(*itr);
}
}
@@ -300,10 +301,11 @@ void AbstractDBusInterface::registerObject()
DebugOut()<<"registering DBus path: "<<mObjectPath<<endl;
regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, this, NULL, &error2);
-
+ g_dbus_node_info_unref(introspection);
if(error2)
{
DebugOut(DebugOut::Error)<<error2->message<<endl;
+ g_error_free(error2);
}
if(regId == 0)
diff --git a/plugins/dbus/abstractproperty.cpp b/plugins/dbus/abstractproperty.cpp
index 3a818312..8c444c60 100644
--- a/plugins/dbus/abstractproperty.cpp
+++ b/plugins/dbus/abstractproperty.cpp
@@ -26,6 +26,14 @@ AbstractProperty::AbstractProperty(string pn, Access access, AbstractDBusInterfa
}
+AbstractProperty::~AbstractProperty()
+{
+ if(mValue){
+ delete mValue;
+ mValue = nullptr;
+ }
+}
+
void AbstractProperty::updateValue()
{
mInterface->updateValue(this);
diff --git a/plugins/dbus/abstractproperty.h b/plugins/dbus/abstractproperty.h
index 2049f1c3..c2a362b1 100644
--- a/plugins/dbus/abstractproperty.h
+++ b/plugins/dbus/abstractproperty.h
@@ -47,6 +47,7 @@ public:
};
AbstractProperty(string propertyName, Access access, AbstractDBusInterface* interface);
+ virtual ~AbstractProperty();
virtual void setSetterFunction(SetterFunc setterFunc)
{
diff --git a/plugins/dbus/automotivemanager.cpp b/plugins/dbus/automotivemanager.cpp
index 972f08f6..304a54fc 100644
--- a/plugins/dbus/automotivemanager.cpp
+++ b/plugins/dbus/automotivemanager.cpp
@@ -245,8 +245,12 @@ AutomotiveManager::AutomotiveManager(GDBusConnection *connection)
GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, "org.automotive.Manager");
regId = g_dbus_connection_register_object(mConnection, "/", mInterfaceInfo, &interfaceVTable, this, NULL, &error);
+ g_dbus_node_info_unref(introspection);
- if(error) throw -1;
+ if(error){
+ g_error_free(error);
+ throw -1;
+ }
g_assert(regId > 0);
}
diff --git a/plugins/dbus/custompropertyinterface.cpp b/plugins/dbus/custompropertyinterface.cpp
index 06894a5d..b9d13a5a 100644
--- a/plugins/dbus/custompropertyinterface.cpp
+++ b/plugins/dbus/custompropertyinterface.cpp
@@ -17,7 +17,9 @@ CustomPropertyInterface::CustomPropertyInterface(VehicleProperty::Property prop,
throw std::runtime_error("Cannot create custom property: " + prop);
}
- std::string signature = g_variant_get_type_string(temp->toVariant());
+ GVariant* var = temp->toVariant();
+ std::string signature = g_variant_get_type_string(var);
+ g_variant_unref(var);
propertyDBusMap[prop] = new VariantType(re, signature, prop, prop, VariantType::ReadWrite, this);
diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp
index f5e3664f..8d1e95b4 100644
--- a/plugins/dbus/dbusplugin.cpp
+++ b/plugins/dbus/dbusplugin.cpp
@@ -78,8 +78,17 @@ const string DBusSink::uuid()
return "c2e6cafa-eef5-4b8a-99a0-0f2c9be1057d";
}
-DBusSinkManager::DBusSinkManager(AbstractRoutingEngine *engine, map<string, string> config)
- :AbstractSinkManager(engine, config)
+DBusSinkManager::DBusSinkManager(AbstractRoutingEngine *engine, map<string, string> config) :
+ AbstractSinkManager(engine, config),
+ manager(nullptr)
{
- DBusInterfaceManager* manager = new DBusInterfaceManager(engine, config);
+ manager = new DBusInterfaceManager(engine, config);
+}
+
+DBusSinkManager::~DBusSinkManager()
+{
+ if(manager){
+ delete manager;
+ manager = nullptr;
+ }
}
diff --git a/plugins/dbus/dbusplugin.h b/plugins/dbus/dbusplugin.h
index c4b98398..de936998 100644
--- a/plugins/dbus/dbusplugin.h
+++ b/plugins/dbus/dbusplugin.h
@@ -34,7 +34,12 @@ class DBusSink : public AbstractSink, public AbstractDBusInterface
public:
DBusSink(std::string objectName, AbstractRoutingEngine* engine, GDBusConnection* connection, map<string, string> config);
- virtual ~DBusSink() { }
+ virtual ~DBusSink() {
+ for(auto itr = propertyDBusMap.begin(); itr != propertyDBusMap.end(); ++itr)
+ {
+ delete itr->second;
+ }
+ }
virtual void supportedChanged(PropertyList supportedProperties);
virtual void propertyChanged(AbstractPropertyType *value);
virtual const std::string uuid();
@@ -84,10 +89,13 @@ protected:
};
+class DBusInterfaceManager;
class DBusSinkManager: public AbstractSinkManager
{
+ DBusInterfaceManager* manager;
public:
DBusSinkManager(AbstractRoutingEngine* engine, map<string, string> config);
+ ~DBusSinkManager();
};
#endif
diff --git a/plugins/dbus/environmentproperties.h b/plugins/dbus/environmentproperties.h
index e7f9ac76..5f8073b2 100644
--- a/plugins/dbus/environmentproperties.h
+++ b/plugins/dbus/environmentproperties.h
@@ -161,7 +161,8 @@ public:
* @access readwrite
* @attributeComment \brief Must return air recirculation on (true) / off (false).
*/
- wantPropertyVariant(VehicleProperty::AirRecirculation, "AirRecirculation", "b", AbstractProperty::ReadWrite);
+ //DUPLICATED!
+ //wantPropertyVariant(VehicleProperty::AirRecirculation, "AirRecirculation", "b", AbstractProperty::ReadWrite);
/**
* @attributeName SteeringWheelHeater
diff --git a/plugins/dbus/uncategorizedproperty.cpp b/plugins/dbus/uncategorizedproperty.cpp
index 83ea0f1e..034a9587 100644
--- a/plugins/dbus/uncategorizedproperty.cpp
+++ b/plugins/dbus/uncategorizedproperty.cpp
@@ -13,7 +13,9 @@ UncategorizedPropertyInterface::UncategorizedPropertyInterface(VehicleProperty::
throw std::runtime_error("Cannot create uncategorized property: " + prop);
}
- std::string signature = g_variant_get_type_string(temp->toVariant());
+ GVariant* var = temp->toVariant();
+ std::string signature = g_variant_get_type_string(var);
+ g_variant_unref(var);
propertyDBusMap[prop] = new VariantType(re, signature, prop, prop, VariantType::ReadWrite, this);
diff --git a/plugins/dbus/varianttype.cpp b/plugins/dbus/varianttype.cpp
index ea7983d1..047c6e78 100644
--- a/plugins/dbus/varianttype.cpp
+++ b/plugins/dbus/varianttype.cpp
@@ -48,7 +48,7 @@ GVariant *VariantType::toGVariant()
setValue(v);
- delete v;
+ delete v; //TODO: Needs to be veriefied if it will CRASH here. Does setValue() take ownership ???
}
auto v = value();
diff --git a/plugins/gpsd/gpsdplugin.cpp b/plugins/gpsd/gpsdplugin.cpp
index e234516d..c08908de 100644
--- a/plugins/gpsd/gpsdplugin.cpp
+++ b/plugins/gpsd/gpsdplugin.cpp
@@ -46,7 +46,7 @@ static int updateGpsposition(gpointer data)
}
#else
- gps_poll(&gps);
+ gps_poll(&shared->gps);
#endif