fix msg-manager crash issue 79/91879/2 accepted/tizen/common/20161012.154611 accepted/tizen/ivi/20161013.000710 accepted/tizen/mobile/20161013.000639 accepted/tizen/wearable/20161013.000654 submit/tizen/20161012.062243
authorKyeonghun Lee <kh9090.lee@samsung.com>
Wed, 12 Oct 2016 05:20:26 +0000 (14:20 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Wed, 12 Oct 2016 06:18:41 +0000 (15:18 +0900)
Change-Id: I6463279827f80bc4ea845f5dcd42648d44551571
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
manager/src/msg-manager-notification.cpp

index 2f85874..760a114 100644 (file)
@@ -1750,7 +1750,30 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
                MSG_MGR_SEC_DEBUG("sender info = [%s]", noti_info->sender);
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, MAX_QUERY_LEN,
+                               "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS SMS_UNREAD_CNT, "
+                               "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS MMS_UNREAD_CNT "
+                               "FROM %s WHERE READ_STATUS = 0;",
+                               MSG_SMS_TYPE,
+                               MSG_MMS_TYPE,
+                               MSGFW_MESSAGE_TABLE_NAME);
+
+               MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
+
+               msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
+               if (msg_err != MSG_SUCCESS) {
+                       MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
+                       return -1;
+               }
 
+               if (row_cnt > 0) {
+                       smsUnreadCnt = atoi(db_res[col_cnt]);
+                       mmsUnreadCnt = atoi(db_res[col_cnt+1]);
+               }
+
+               msg_db_free(msg_handle, db_res);
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
 #ifdef MSG_NOTI_INTEGRATION
                snprintf(sqlQuery, sizeof(sqlQuery),
                                "A.ADDRESS_VAL, "
@@ -1760,8 +1783,6 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
                                "(CASE WHEN B.DPM_RESTRICTED = 0 THEN B.MSG_TEXT ELSE \"restricted message\" END), "
                                "B.MAIN_TYPE, "
                                "B.CONV_ID, "
-                               "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d AND B.READ_STATUS = 0 THEN B.MSG_ID END))) AS SMS_UNREAD_CNT, "
-                               "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d AND B.READ_STATUS = 0 THEN B.MSG_ID END))) AS MMS_UNREAD_CNT, "
                                "(CASE WHEN B.MAIN_TYPE = %d AND B.NETWORK_STATUS = %d THEN (SELECT C.MSG_SIZE FROM %s C WHERE B.MSG_ID = C.MSG_ID) ELSE -1 END), "
                                "B.ATTACHMENT_COUNT "
                                "FROM %s B "
@@ -1769,8 +1790,6 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
                                "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
                                "AND B.STORAGE_ID = %d "
                                "ORDER BY B.DISPLAY_TIME DESC;",
-                               MSG_SMS_TYPE,
-                               MSG_MMS_TYPE,
                                MSG_MMS_TYPE, MSG_NETWORK_RECEIVED, MMS_PLUGIN_MESSAGE_TABLE_NAME,
                                MSGFW_MESSAGE_TABLE_NAME,
                                MSGFW_ADDRESS_TABLE_NAME,
@@ -1806,10 +1825,8 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
                }
 
                if (row_cnt > 0) {
-                       smsUnreadCnt = atoi(db_res[col_cnt+7]);
-                       mmsUnreadCnt = atoi(db_res[col_cnt+8]);
-                       msgSize = atoi(db_res[col_cnt+9]);
-                       attachmentCnt = atoi(db_res[col_cnt+10]);
+                       msgSize = atoi(db_res[col_cnt+7]);
+                       attachmentCnt = atoi(db_res[col_cnt+8]);
 
                        noti_info->count = smsUnreadCnt + mmsUnreadCnt;