From: Jiyong Min Date: Mon, 16 Oct 2017 01:39:39 +0000 (+0900) Subject: Fix callback not invoked for specific path and memory leak of media_callback_data X-Git-Tag: accepted/tizen/unified/20171016.064712^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F155633%2F2;p=platform%2Fcore%2Fmultimedia%2Fmedia-server.git Fix callback not invoked for specific path and memory leak of media_callback_data Change-Id: I0c53dee767cc3ac6c660f76a4ffe97bafdccbe0a Signed-off-by: Jiyong Min --- diff --git a/lib/media-util-register.c b/lib/media-util-register.c index 2f93eff..76ccbaf 100755 --- a/lib/media-util-register.c +++ b/lib/media-util-register.c @@ -273,6 +273,7 @@ static int _remove_request(const char * req_path) MS_SAFE_FREE(sock_path); } + MS_SAFE_FREE(req_data->cb_data); MS_SAFE_FREE(req_data->req_path); MS_SAFE_FREE(req_data); @@ -331,6 +332,7 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *s int request_msg_size = 0; int sockfd = -1; ms_comm_msg_s send_msg; + char *request_path = NULL; if (!MS_STRING_VALID(request_msg)) { MSAPI_DBG_ERR("invalid query"); @@ -345,29 +347,43 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *s return MS_MEDIA_ERR_INVALID_PARAMETER; } - MSAPI_DBG("querysize[%d] query[%s]", request_msg_size, request_msg); + if (request_msg[request_msg_size - 1] == '/') { + request_path = g_strndup(request_msg, request_msg_size - 1); + request_msg_size = request_msg_size - 1; + } else { + request_path = g_strdup(request_msg); + } + MSAPI_RETVM_IF(request_path == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); + + MSAPI_DBG("querysize[%d] path[%s] query[%s]", request_msg_size, request_msg, request_path); memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s)); send_msg.msg_type = msg_type; send_msg.pid = syscall(__NR_getpid); send_msg.msg_size = request_msg_size; send_msg.uid = uid; - SAFE_STRLCPY(send_msg.msg, request_msg, sizeof(send_msg.msg)); + SAFE_STRLCPY(send_msg.msg, request_path, sizeof(send_msg.msg)); if (MS_STRING_VALID(storage_id)) SAFE_STRLCPY(send_msg.storage_id, storage_id, sizeof(send_msg.storage_id)); /*Create Socket*/ ret = ms_ipc_create_client_socket(0, &sockfd); - MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); + if (ret != MS_MEDIA_ERR_NONE) { + MSAPI_DBG_ERR("ms_ipc_create_client_socket failed : %d", ret); + MS_SAFE_FREE(request_path); + return ret; + } ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL); if (ret != MS_MEDIA_ERR_NONE) { MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret); + MS_SAFE_FREE(request_path); close(sockfd); return ret; } - ret = _attach_callback(request_msg, &sockfd, NULL, user_callback, user_data); + ret = _attach_callback(request_path, &sockfd, NULL, user_callback, user_data); + MS_SAFE_FREE(request_path); return ret; } @@ -378,6 +394,7 @@ static int __media_db_request_update_cancel(ms_msg_type_e msg_type, const char * int request_msg_size = 0; int sockfd = -1; ms_comm_msg_s send_msg; + char *request_path = NULL; if (!MS_STRING_VALID(request_msg)) { MSAPI_DBG_ERR("invalid query"); @@ -392,21 +409,38 @@ static int __media_db_request_update_cancel(ms_msg_type_e msg_type, const char * return MS_MEDIA_ERR_INVALID_PARAMETER; } + if (request_msg[request_msg_size - 1] == '/') { + request_path = g_strndup(request_msg, request_msg_size - 1); + request_msg_size = request_msg_size - 1; + } else { + request_path = g_strdup(request_msg); + } + MSAPI_RETVM_IF(request_path == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); + memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s)); send_msg.msg_type = msg_type; send_msg.pid = syscall(__NR_getpid); send_msg.msg_size = request_msg_size; - SAFE_STRLCPY(send_msg.msg, request_msg, sizeof(send_msg.msg)); + SAFE_STRLCPY(send_msg.msg, request_path, sizeof(send_msg.msg)); /*Create Socket*/ ret = ms_ipc_create_client_socket(0, &sockfd); - MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); + if (ret != MS_MEDIA_ERR_NONE) { + MSAPI_DBG_ERR("ms_ipc_create_client_socket failed : %d", ret); + MS_SAFE_FREE(request_path); + return ret; + } ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL); close(sockfd); - MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_ipc_send_msg_to_server failed : %d", ret); + if (ret != MS_MEDIA_ERR_NONE) { + MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret); + MS_SAFE_FREE(request_path); + return ret; + } - ret = _remove_request(request_msg); + ret = _remove_request(request_path); + MS_SAFE_FREE(request_path); return ret; } diff --git a/packaging/media-server.spec b/packaging/media-server.spec index dbbdd12..d426d57 100755 --- a/packaging/media-server.spec +++ b/packaging/media-server.spec @@ -1,6 +1,6 @@ Name: media-server Summary: A server for media content management -Version: 0.3.56 +Version: 0.3.57 Release: 0 Group: Multimedia/Service License: Apache-2.0