Fix mem leak. 22/139522/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Wed, 19 Jul 2017 08:10:03 +0000 (17:10 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Wed, 19 Jul 2017 08:10:03 +0000 (17:10 +0900)
Change-Id: Idfe461d060344ddd333307ef34a10c12030a6e28
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-api/bt-common.c [changed mode: 0755->0644]
bt-api/bt-gatt-service.c
bt-api/bt-telephony.c
bt-httpproxy/bt-httpproxy.c
bt-service/bt-request-handler.c

old mode 100755 (executable)
new mode 100644 (file)
index 4e15b7f..be29354
@@ -672,7 +672,6 @@ static GDBusConnection *gconn;
 static int latest_id = -1;
 #define BT_RFCOMM_ID_MAX 245
 static gboolean id_used[BT_RFCOMM_ID_MAX];
-GDBusNodeInfo *new_conn_node;
 
 static const gchar rfcomm_agent_xml[] =
 "<node name='/'>"
@@ -883,6 +882,7 @@ void _bt_unregister_gdbus(int object_id)
 int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
 {
        GDBusConnection *gconn;
+       GDBusNodeInfo *node_info;
        int id;
        GError *error = NULL;
 
@@ -890,16 +890,15 @@ int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
        if (gconn == NULL)
                return -1;
 
-       if (new_conn_node == NULL)
-               new_conn_node = _bt_get_gdbus_node(rfcomm_agent_xml);
-
-       if (new_conn_node == NULL)
+       node_info = _bt_get_gdbus_node(rfcomm_agent_xml);
+       if (node_info == NULL)
                return -1;
 
        id = g_dbus_connection_register_object(gconn, path,
-                                               new_conn_node->interfaces[0],
+                                               node_info->interfaces[0],
                                                &method_table,
                                                cb, NULL, &error);
+       g_dbus_node_info_unref(node_info);
        if (id == 0) {
                BT_ERR("Failed to register: %s", error->message);
                g_error_free(error);
@@ -983,6 +982,7 @@ fail:
 int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_connection_cb cb)
 {
        GDBusConnection *gconn;
+       GDBusNodeInfo *node_info;
        int id;
        GError *error = NULL;
 
@@ -990,16 +990,16 @@ int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_conn
        if (gconn == NULL)
                return -1;
 
-       if (new_conn_node == NULL)
-               new_conn_node = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
+       node_info = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
 
-       if (new_conn_node == NULL)
+       if (node_info == NULL)
                return -1;
 
        id = g_dbus_connection_register_object(gconn, path,
-                                               new_conn_node->interfaces[0],
+                                               node_info->interfaces[0],
                                                &method_table,
                                                cb, NULL, &error);
+       g_dbus_node_info_unref(node_info);
        if (id == 0) {
                BT_ERR("Failed to register: %s", error->message);
                g_error_free(error);
index 969fc83..3fc4685 100644 (file)
@@ -1518,6 +1518,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
+               g_free(address);
                if (!g_conn) {
                        if (err) {
                                BT_ERR("Unable to connect to dbus: %s", err->message);
@@ -1541,7 +1542,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
-
+               g_free(address);
                if (!local_system_gconn) {
                        BT_ERR("Unable to connect to dbus: %s", err->message);
                        g_clear_error(&err);
@@ -1585,7 +1586,6 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
        /* Register ObjectManager interface */
        node_info = __bt_gatt_create_method_node_info(
                                        manager_introspection_xml);
-
        if (node_info == NULL) {
                BT_ERR("failed to get node info");
                goto failed;
@@ -1599,7 +1599,7 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
                                                        &manager_interface_vtable,
                                                        NULL, NULL, &error);
        }
-
+       g_dbus_node_info_unref(node_info);
        if (manager_id == 0) {
                BT_ERR("failed to register: %s", error->message);
                g_error_free(error);
@@ -1680,7 +1680,6 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
 
        node_info = __bt_gatt_create_method_node_info(
                                        service_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1691,6 +1690,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
                                        node_info->interfaces[0],
                                        &serv_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1784,7 +1784,6 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        node_info = __bt_gatt_create_method_node_info(
                                        characteristics_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1795,6 +1794,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                                        node_info->interfaces[0],
                                        &char_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1985,7 +1985,6 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        node_info = __bt_gatt_create_method_node_info(
                                        descriptor_introspection_xml);
-
        if (node_info == NULL) {
                g_strfreev(line_argv);
                g_free(serv_path);
@@ -1999,6 +1998,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                                node_info->interfaces[0],
                                &desc_interface_vtable,
                                NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
index fd437b5..837848c 100644 (file)
@@ -703,7 +703,6 @@ static int __bluetooth_telephony_proxy_init(void)
 
        node_info = __bt_telephony_create_method_node_info(
                                bt_telephony_introspection_xml);
-
        if (node_info == NULL) {
                BT_ERR("node_info NULL");
                return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
@@ -711,10 +710,12 @@ static int __bluetooth_telephony_proxy_init(void)
        if (__bluetooth_telephony_register_object(TRUE, node_info) !=
                        BLUETOOTH_TELEPHONY_ERROR_NONE) {
                BT_ERR("Registation of Method Failed");
+               g_dbus_node_info_unref(node_info);
                return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
        }
 
        FN_END;
+       g_dbus_node_info_unref(node_info);
        return BLUETOOTH_TELEPHONY_ERROR_NONE;
 }
 
index c8b1e4e..4d23471 100644 (file)
@@ -69,7 +69,6 @@ static GSList *hps_char_list = NULL;
 static GDBusConnection *conn;
 static GDBusConnection *g_conn;
 static guint g_owner_id = 0;
-GDBusNodeInfo *hps_node_info = NULL;
 
 char *g_uri = NULL;
 char *g_header = NULL;
@@ -202,6 +201,7 @@ static const GDBusInterfaceVTable hps_method_table = {
 
 static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
+       GDBusNodeInfo *node_info = NULL;
        guint object_id;
        GError *error = NULL;
 
@@ -209,14 +209,21 @@ static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *na
 
        g_conn = connection;
 
+       node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error);
+       if (!node_info) {
+               BT_ERR("Failed to install: %s", error->message);
+               g_clear_error(&error);
+               return;
+       }
+
        object_id = g_dbus_connection_register_object(connection, BT_HPS_OBJECT_PATH,
-                                               hps_node_info->interfaces[0],
+                                               node_info->interfaces[0],
                                                &hps_method_table,
                                                NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
        if (object_id == 0) {
                BT_ERR("Failed to register method table: %s", error->message);
                g_error_free(error);
-               g_dbus_node_info_unref(hps_node_info);
        }
 
        return;
@@ -237,7 +244,6 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection,
        BT_DBG("");
        g_object_unref(g_conn);
        g_conn = NULL;
-       g_dbus_node_info_unref(hps_node_info);
        g_bus_unown_name(g_owner_id);
 
        return;
@@ -245,17 +251,10 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection,
 
 int _bt_hps_register_interface(void)
 {
-       GError *error = NULL;
        guint owner_id;
 
        BT_DBG("");
 
-       hps_node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error);
-       if (!hps_node_info) {
-               BT_ERR("Failed to install: %s", error->message);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                BT_HPS_SERVICE_NAME,
                                G_BUS_NAME_OWNER_FLAGS_NONE,
@@ -273,7 +272,6 @@ void _bt_hps_unregister_interface(void)
 
        g_object_unref(g_conn);
        g_conn = NULL;
-       g_dbus_node_info_unref(hps_node_info);
        g_bus_unown_name(g_owner_id);
 
        return;
index 61d038a..f955a97 100644 (file)
@@ -72,7 +72,6 @@ static const gchar bt_service_introspection_xml[] =
 "      </interface>"
 "</node>";
 
-GDBusNodeInfo *node_info = NULL;
 static gboolean name_acquired = FALSE;
 
 static char *current_sender_playing = NULL;
@@ -3310,18 +3309,18 @@ int __bt_service_register_object(GDBusConnection *conn,
 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
                const gchar *name, gpointer user_data)
 {
+       GDBusNodeInfo *node_info = NULL;
+
        BT_INFO("bus acquired");
 
        ret_if(connection == NULL);
 
        node_info = __bt_service_create_method_node_info(
                        bt_service_introspection_xml);
-
        ret_if(node_info == NULL);
 
        __bt_service_register_object(connection, node_info, TRUE);
        g_dbus_node_info_unref(node_info);
-       node_info = NULL;
 
        bt_service_conn = connection;
 }
@@ -3384,10 +3383,6 @@ void _bt_service_unregister(void)
                        g_object_unref(bt_service_conn);
                        bt_service_conn = NULL;
                }
-               if (node_info) {
-                       g_dbus_node_info_unref(node_info);
-                       node_info = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;