From 97cbb46673d765b72eed4b02d5a6732538c926ca Mon Sep 17 00:00:00 2001 From: Marek Timko Date: Fri, 22 Nov 2013 12:53:05 +0100 Subject: 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 --- ambd/glibmainloop.cpp | 1 + ambd/pluginloader.cpp | 32 +++++++++++++++++++++++++++++--- ambd/pluginloader.h | 14 ++++---------- lib/abstractroutingengine.cpp | 3 ++- lib/abstractsink.h | 1 + lib/mappropertytype.hpp | 1 + lib/vehicleproperty.cpp | 11 +++++++++++ lib/vehicleproperty.h | 5 +++++ plugins/dbus/abstractdbusinterface.cpp | 6 ++++-- plugins/dbus/abstractproperty.cpp | 8 ++++++++ plugins/dbus/abstractproperty.h | 1 + plugins/dbus/automotivemanager.cpp | 6 +++++- plugins/dbus/custompropertyinterface.cpp | 4 +++- plugins/dbus/dbusplugin.cpp | 15 ++++++++++++--- plugins/dbus/dbusplugin.h | 10 +++++++++- plugins/dbus/environmentproperties.h | 3 ++- plugins/dbus/uncategorizedproperty.cpp | 4 +++- plugins/dbus/varianttype.cpp | 2 +- plugins/gpsd/gpsdplugin.cpp | 2 +- 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__<<" "<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: "< mSinks; create_t * f_create; create_mainloop_t * m_create; IMainLoop* mMainLoop; + + std::vector 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 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::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: "<message<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 config) - :AbstractSinkManager(engine, config) +DBusSinkManager::DBusSinkManager(AbstractRoutingEngine *engine, map 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 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 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 -- cgit v1.2.1