Clean the logic in communication layer 85/31785/1 accepted/tizen/common/20141210.165735 submit/tizen_common/20141210.090430
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 9 Dec 2014 18:59:30 +0000 (19:59 +0100)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 9 Dec 2014 19:01:40 +0000 (20:01 +0100)
Fix possible memory leak in case where the connection is not in connected state it were never free'd
Don't register the connection in gmainloop => this leads to crash in stress test

Bug-Tizen=TC-1808
Change-Id: If80e0ae2d33c115f62374c4bdb7030cc2bd6f11a
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
comm/comm_client_dbus.c

index 63c7fe5..1518bde 100644 (file)
@@ -280,11 +280,7 @@ comm_client *comm_client_new(void)
                ERR("dbus connection is not set, even dbus error isn't raised");
                goto ERROR_CLEANUP;
        }
-
-       /* TODO: requesting name for dbus is needed? */
-
-       /* Register my connection to g_main_loop (with default context) */
-       dbus_connection_setup_with_g_main(cc->conn, NULL);
+       dbus_connection_set_exit_on_disconnect(cc->conn,FALSE);
 
        return cc;
 
@@ -301,27 +297,26 @@ int comm_client_free(comm_client *cc)
 {
        if (!cc)
                return -1;
-       if (!(cc->conn) || !dbus_connection_get_is_connected(cc->conn)) {
+       if (!(cc->conn) {
                ERR("Invalid dbus connection");
                return -2;
        }
 
-       /* Cleanup ADT */
-       /* flush remaining buffer: blocking mode */
-       dbus_connection_flush(cc->conn);
-
        /* Free signal filter if signal callback is exist */
        if (cc->sig_cb_data) {
                dbus_connection_remove_filter(cc->conn,
                                              _on_signal_handle_filter,
                                              cc->sig_cb_data);
-               /* TODO: Is it needed to free cc->sig_cb_data here? */
-               /* _free_sig_cb_data(cc->sig_cb_data); */
+               cc->sig_cb_data = NULL;
+       }
+       if (dbus_connection_get_is_connected(cc->conn)) {
+       /* Cleanup ADT */
+       /* flush remaining buffer: blocking mode */
+               dbus_connection_flush(cc->conn);
        }
-
        dbus_connection_close(cc->conn);
        dbus_connection_unref(cc->conn);
-
+       cc->conn = NULL;
        free(cc);
 
        return 0;