Fix __dispatch_get_socket_pair resource leak. 20/53220/3
authorhyunho kang <hhstark.kang@samsung.com>
Thu, 3 Dec 2015 01:05:42 +0000 (10:05 +0900)
committerhyunho kang <hhstark.kang@samsung.com>
Thu, 3 Dec 2015 01:44:58 +0000 (10:44 +0900)
Change-Id: I5158f0e69da8e660a10cdb6e8997bab0add6ef5f
Signed-off-by: hyunho kang <hhstark.kang@samsung.com>
am_daemon/amd_request.c

index 637c78b..d412810 100644 (file)
@@ -363,6 +363,7 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc
        caller = (char *)bundle_get_val(kb, AUL_K_CALLER_APPID);
        callee = (char *)bundle_get_val(kb, AUL_K_CALLEE_APPID);
        datacontrol_type = (char *)bundle_get_val(kb, "DATA_CONTOL_TYPE");
+       bundle_free(kb);
 
        socket_pair_key_len = strlen(caller) + strlen(callee) + 2;
 
@@ -373,7 +374,7 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc
        }
 
        snprintf(socket_pair_key, socket_pair_key_len, "%s_%s", caller, callee);
-       _E("socket pair key : %s", socket_pair_key);
+       _D("socket pair key : %s", socket_pair_key);
 
        handles = g_hash_table_lookup(__socket_pair_hash, socket_pair_key);
        if (handles == NULL) {
@@ -381,18 +382,28 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc
                if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0) {
                        _E("error create socket pair");
                        __send_result_to_client(clifd, -1);
-                       goto err_out;
+
+                       if (handles)
+                               free(handles);
+                       if (socket_pair_key)
+                               free(socket_pair_key);
+                       return -1;
                }
 
                if (handles[0] == -1) {
                        _E("error socket open");
                        __send_result_to_client(clifd, -1);
-                       goto err_out;
+
+                       if (handles)
+                               free(handles);
+                       if (socket_pair_key)
+                               free(socket_pair_key);
+                       return -1;
                }
                g_hash_table_insert(__socket_pair_hash, strdup(socket_pair_key),
                                handles);
 
-               _E("New socket pair insert done.");
+               _D("New socket pair insert done.");
        }
 
 
@@ -404,7 +415,7 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc
        vec[0].iov_len = strlen(buffer) + 1;
 
        if (datacontrol_type != NULL) {
-               _E("datacontrol_type : %s", datacontrol_type);
+               _D("datacontrol_type : %s", datacontrol_type);
                if (strcmp(datacontrol_type, "consumer") == 0) {
                        msglen = __send_message(clifd, vec, 1, &handles[0], 1);
                        if (msglen < 0) {
@@ -435,12 +446,13 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc
                }
        }
        SECURE_LOGD("send_message msglen : [%d]\n", msglen);
+       if (socket_pair_key)
+               free(socket_pair_key);
 
        return 0;
 
 err_out:
-       if (handles)
-               free(handles);
+       g_hash_table_remove(__socket_pair_hash, socket_pair_key);
        if (socket_pair_key)
                free(socket_pair_key);
 
@@ -1074,7 +1086,7 @@ int _request_init(void)
        GPollFD *gpollfd;
        GSource *src;
 
-       __socket_pair_hash = g_hash_table_new_full(g_str_hash,  g_str_equal, NULL, g_free);
+       __socket_pair_hash = g_hash_table_new_full(g_str_hash,  g_str_equal, free, free);
 
        fd = __create_sock_activation();
        if (fd == -1) {