plugged some memory leaks 47/9947/1
authorKevron Rees <kevron.m.rees@intel.com>
Wed, 11 Sep 2013 20:44:19 +0000 (13:44 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Wed, 11 Sep 2013 20:44:19 +0000 (13:44 -0700)
Change-Id: I2d85df7b9b701523174f66bad3da1b0b756e0a12

src/Vehicle/Vehicle.cpp

index b9cbc0f..32358b1 100644 (file)
@@ -162,10 +162,13 @@ static void signalCallback( GDBusConnection *connection,
        }
        
        master->onSignalReceived(objectName,master->objectToPropertyValuesMap[objectName]);
-       
+
+       g_variant_unref(parameters);
+
        if(valueArray != NULL)
                g_variant_unref(valueArray);
-       //g_free(valueArray);
+
+       g_variant_unref(ifaceName);
 }
 
 std::map<std::string, GVariant*> VehicleMaster::get(std::string property)
@@ -199,6 +202,8 @@ std::map<std::string, GVariant*> VehicleMaster::get(std::string property)
        if(error)
        {
                LoggerD("failed to call GetAll on interface " << interfaceName);
+               g_object_unref(propertiesProxy);
+               g_error_free(error);
                return returnValue;
        }
 
@@ -213,6 +218,7 @@ std::map<std::string, GVariant*> VehicleMaster::get(std::string property)
                returnValue[key] = value;
        }
 
+       g_object_unref(propertiesProxy);
        return returnValue;
 }
 
@@ -246,6 +252,8 @@ void VehicleMaster::subscribe(std::string objectName, JSObjectRef successCallbac
 
                GVariant* propertyMap = g_dbus_proxy_call_sync(propertiesProxy, "GetAll", g_variant_new("(s)", interfaceName.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
+               g_object_unref(propertiesProxy);
+
                if(error)
                {
                        LoggerD("failed to call GetAll on interface " << interfaceName<< " "<<error->message);
@@ -307,12 +315,6 @@ std::string VehicleMaster::findProperty(std::string objectName)
        
        GVariant* objectPath = g_dbus_proxy_call_sync(managerProxy, "findProperty", g_variant_new("(s)", objectName.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
-       if(!objectPath)
-       {
-               LoggerD("Could not find property");
-               return ""; 
-       }
-
        if(error)
        {
                LoggerD("error calling findProperty "<< error->message);
@@ -320,6 +322,12 @@ std::string VehicleMaster::findProperty(std::string objectName)
                return "";
        }
 
+       if(!objectPath)
+       {
+               LoggerD("Could not find property");
+               return "";
+       }
+
        LoggerD("returned object path: " << g_variant_get_type_string(objectPath));
 
        gchar * objP;
@@ -327,10 +335,9 @@ std::string VehicleMaster::findProperty(std::string objectName)
 
        LoggerD("findProperty() returned object path: " <<objP);
 
-       g_variant_unref(objectPath);    
+       g_variant_unref(objectPath);
 
        return objP;
-       
 }
 
 void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::string, GVariant*> propertyMap)