Memory leak fix and use g_strlcpy instead of strncpy. 78/124878/3 accepted/tizen/unified/20170413.162451 submit/tizen/20170413.020954
authorHaejeong Kim <backto.kim@samsung.com>
Thu, 13 Apr 2017 01:42:41 +0000 (10:42 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Thu, 13 Apr 2017 01:45:13 +0000 (10:45 +0900)
Change-Id: I14e7846b824ffa4ab00a16c677f6679b825b659c

packaging/dcm-service.spec
src/DcmDbUtils.cpp
src/DcmFaceUtils.cpp
src/DcmIpcUtils.cpp

index 86441e69c545cfefc52636d39e4834633654816d..55b95cbb38b9ca628512ea57eecaaf489e63f096 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       dcm-service
 Summary:    A media DCM(Digital Contents Management) Service
-Version:    0.0.14
+Version:    0.0.15
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index eeb46bd199c7a202953ca01e51661ddf6de08100..3c8edd33b32a66d1964cdcc51519af29f2adbd0a 100755 (executable)
@@ -280,7 +280,6 @@ int DcmDbUtils::_dcm_svc_db_get_scan_image_list_by_path(GList **image_list, bool
                return TRUE;
        }
 
-       
        while(sqlite3_step(sql_stmt) == SQLITE_ROW) {
                DcmScanItem *scan_item = (DcmScanItem *) g_malloc0(sizeof(DcmScanItem));
                if (!scan_item) {
@@ -300,8 +299,7 @@ int DcmDbUtils::_dcm_svc_db_get_scan_image_list_by_path(GList **image_list, bool
                scan_item->image_width = sqlite3_column_int(sql_stmt, 2);
                scan_item->image_height = sqlite3_column_int(sql_stmt, 3);
                scan_item->image_orientation = sqlite3_column_int(sql_stmt, 4);
-               if (DCM_STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 5)))
-                       scan_item->mime_type = strdup((const char *)sqlite3_column_text(sql_stmt, 5));
+               scan_item->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 5));
 
                /* scan item retrieved by this function will be marked as SCAN_SINGLE */
                scan_item->scan_item_type = DCM_SCAN_ITEM_TYPE_SCAN_SINGLE;
@@ -310,7 +308,6 @@ int DcmDbUtils::_dcm_svc_db_get_scan_image_list_by_path(GList **image_list, bool
 
                dcm_sec_debug("media uuid: [%s] file path: [%s]", scan_item->media_uuid, scan_item->file_path);
        }
-       
 
        DCM_SQLITE3_FINALIZE(sql_stmt);
 
@@ -362,8 +359,7 @@ int DcmDbUtils::_dcm_svc_db_get_scan_image_list_from_db(GList **image_list, bool
                scan_item->image_width = sqlite3_column_int(sql_stmt, 3);
                scan_item->image_height = sqlite3_column_int(sql_stmt, 4);
                scan_item->image_orientation = sqlite3_column_int(sql_stmt, 5);
-               if (DCM_STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 6)))
-                       scan_item->mime_type = strdup((const char *)sqlite3_column_text(sql_stmt, 6));
+               scan_item->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 6));
 
                /* scan item retrieved by this function will be marked as SCAN_ALL */
                scan_item->scan_item_type = DCM_SCAN_ITEM_TYPE_SCAN_ALL;
@@ -392,7 +388,7 @@ int DcmDbUtils::_dcm_svc_db_generate_uuid(DcmFaceItem **face)
        uuid_generate(uuid_value);
        uuid_unparse(uuid_value, uuid_unparsed);
 
-       (*face)->face_uuid = strdup(uuid_unparsed);
+       (*face)->face_uuid = g_strdup(uuid_unparsed);
 
        if ((*face)->face_uuid == NULL) {
                ret = DCM_ERROR_UUID_GENERATE_FAILED;
index 6d1764fdb5e1acabc38b3cb6dbd03dc71ed5ca73..f5d5b0945d9d1c6cdf7635845381102374529b38 100755 (executable)
@@ -184,9 +184,7 @@ DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED:
                dcm_error("Failed to insert face item into face_scan_list! err: %d", err);
        }
 
-       if (face_info != NULL && face_info->count > 0) {
-               dcm_face_destroy_face_info(face_info);
-       }
+       dcm_face_destroy_face_info(face_info);
 
        if (face != NULL) {
                DcmFaceApi::freeDcmFaceItem(face);
index 19b1016dfbbdaf0e9210e12b9016a8a5f3b23332..7d347eabb763338846f0c486c3f96baa7953847f 100755 (executable)
@@ -180,7 +180,7 @@ int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsi
        send_msg.result = (int)result;
        if (msg != NULL) {
                send_msg.msg_size = strlen(msg);
-               strncpy(send_msg.msg, msg, send_msg.msg_size);
+               g_strlcpy(send_msg.msg, msg, DCM_IPC_MSG_MAX_SIZE);
        }
 
        /* If message size is larget than max_size, then message is invalid */
@@ -221,7 +221,7 @@ int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *ms
        send_msg.uid = uid;
        if (msg != NULL) {
                send_msg.msg_size = strlen(msg);
-               strncpy(send_msg.msg, msg, send_msg.msg_size);
+               g_strlcpy(send_msg.msg, msg, DCM_IPC_MSG_MAX_SIZE);
        }
 
        /* If message size is larget than max_size, then message is invalid */
@@ -277,7 +277,7 @@ int DcmIpcUtils::sendCompleteMsg(DcmIpcMsgType msg_type, const unsigned int coun
        send_msg.result = count;
        if (msg != NULL) {
                send_msg.msg_size = strlen(msg);
-               strncpy(send_msg.msg, msg, send_msg.msg_size);
+               g_strlcpy(send_msg.msg, msg, DCM_IPC_MSG_MAX_SIZE);
        }
 
        /* If message size is larget than max_size, then message is invalid */