Fix Memory leak 12/123812/1 accepted/tizen/unified/20170411.035056 submit/tizen/20170411.005908
authorHaejeong Kim <backto.kim@samsung.com>
Fri, 7 Apr 2017 06:16:25 +0000 (15:16 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Fri, 7 Apr 2017 06:16:25 +0000 (15:16 +0900)
Change-Id: Ie03687a56cd3f157fed792f46478bd1f5b814ded

packaging/capi-media-controller.spec
svc/media_controller_svc.c

index fcc89fc..9470eaa 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-controller
 Summary:    A media controller library in Tizen Native API
-Version:    0.1.34
+Version:    0.1.35
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
index 93b85dd..041af1e 100755 (executable)
@@ -93,12 +93,17 @@ static int __mc_create_request_queue(mc_manage_queue_t **data)
                mc_error("Failed to create queue manager");
                return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
        }
+
        _request->queue = g_queue_new();
+
        if (_request->queue == NULL) {
                mc_error("Failed to create new queue");
+               MC_SAFE_FREE(_request);
                return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
        }
+
        *data = _request;
+
        return MEDIA_CONTROLLER_ERROR_NONE;
 }
 
@@ -162,12 +167,16 @@ static int _mc_service_init(mc_service_t **data)
                mc_error("Failed to allocate service data");
                return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
        }
+
        res = __mc_create_request_queue(&(_service_data->request));
        if (res != MEDIA_CONTROLLER_ERROR_NONE) {
                mc_error("Failed to create queue data");
+               MC_SAFE_FREE(_service_data);
                return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
        }
+
        *data = _service_data;
+
        return MEDIA_CONTROLLER_ERROR_NONE;
 }
 
@@ -265,16 +274,20 @@ static gboolean _mc_service_is_valid_connection(GList *connected_list, mc_comm_m
 static int _mc_service_add_connection(GList **connected_list, mc_comm_msg_s *request_msg)
 {
        mc_debug_fenter();
-       mc_list_data_set_t *data = (mc_list_data_set_t *)calloc(1, sizeof(mc_list_data_set_t));
-       if (data == NULL) {
-               mc_error("memory allocation is failed");
-               return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
-       }
+
+       mc_list_data_set_t *data = NULL;
 
        if (*connected_list != NULL && _mc_service_is_exist_pid(*connected_list, request_msg->pid, request_msg->type)) {
                mc_error("[No-error] connected but do not increase counter [%d]", g_connection_cnt);
                return MEDIA_CONTROLLER_ERROR_NONE;
        }
+
+       data = (mc_list_data_set_t *)calloc(1, sizeof(mc_list_data_set_t));
+       if (data == NULL) {
+               mc_error("memory allocation is failed");
+               return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
+       }
+
        data->pid = request_msg->pid;
        data->type = request_msg->type;
        *connected_list = g_list_append(*connected_list, data);
@@ -479,13 +492,6 @@ gboolean _mc_read_service_request_tcp_socket(GIOChannel *src, GIOCondition condi
 
        mc_debug("mc_read_service_request_tcp_socket is called!!!!!");
 
-       req = (mc_service_request *) calloc(1, sizeof(mc_service_request));
-       if (req == NULL) {
-               mc_error("memory allocation is failed");
-               send_msg = MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
-               goto ERROR;
-       }
-
        sock = g_io_channel_unix_get_fd(src);
        if (sock < 0) {
                mc_error("sock fd is invalid!");
@@ -499,6 +505,14 @@ gboolean _mc_read_service_request_tcp_socket(GIOChannel *src, GIOCondition condi
 
        mc_peer_creds creds;
        memset(&creds, 0x00, sizeof(mc_peer_creds));
+
+       req = (mc_service_request *) calloc(1, sizeof(mc_service_request));
+       if (req == NULL) {
+               mc_error("memory allocation is failed");
+               send_msg = MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
+               goto ERROR;
+       }
+
        req->client_sock = client_sock;
        ret = mc_cynara_receive_untrusted_message(req->client_sock, &recv_msg, &creds);
        if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
@@ -519,7 +533,7 @@ gboolean _mc_read_service_request_tcp_socket(GIOChannel *src, GIOCondition condi
                } else {
                        req->permission = 2;
                }
-       } else {
+       } else {
                req->permission = 1;
        }