msg coverty issue fix
[platform/core/messaging/msg-service.git] / vobject-engine / VMessage.c
index 50da899..cb2bce1 100755 (executable)
@@ -869,7 +869,8 @@ VTree* vmsg_decode(char *pMsgRaw)
                                                pVBody->pTop = NULL;
                                                pVBody->pCur = NULL;
                                                pVBody->pNext = NULL;
-                                               pCurrent->pNext = pVBody;
+                                               if (pCurrent)
+                                                       pCurrent->pNext = pVBody;
                                                pCurrent = pVBody;
                                        }
                                }
@@ -908,12 +909,14 @@ VTree* vmsg_decode(char *pMsgRaw)
                                memset(pTemp, 0, sizeof(VObject));
                                pTemp->property = type;
 
-                               if (pCurrent->pTop == NULL) {
-                                       pCurrent->pTop = pTemp;
-                                       pCurrent->pCur = pTemp;
-                               } else {
-                                       pCurrent->pCur->pSibling = pTemp;
-                                       pCurrent->pCur = pTemp;
+                               if (pCurrent) {
+                                       if (pCurrent->pTop == NULL) {
+                                               pCurrent->pTop = pTemp;
+                                               pCurrent->pCur = pTemp;
+                                       } else {
+                                               pCurrent->pCur->pSibling = pTemp;
+                                               pCurrent->pCur = pTemp;
+                                       }
                                }
 
                                break;
@@ -936,7 +939,8 @@ VTree* vmsg_decode(char *pMsgRaw)
                                        goto CATCH;
 
                                param_status = true;
-                               pCurrent->pCur->pParam = pTmpParam;
+                               if (pCurrent)
+                                       pCurrent->pCur->pParam = pTmpParam;
                                memset(pTmpParam, 0x00, sizeof(VParam));
                                VDATA_TRACE("pTmpParam : %p", pTmpParam);
                        } else {
@@ -1033,8 +1037,11 @@ VTree* vmsg_decode(char *pMsgRaw)
 CATCH:
        VFREE(pTemp);
 CATCH1:
+       VFREE(pTemp);
        VFREE(szMsgBegin);
        VFREE(pMsgRawTmp);
+       VFREE(pTmpParam);
+       VFREE(pVBody);
        vmsg_free_vtree_memory(pVMsg);
        VDATA_TRACE_END
        return NULL;
@@ -1247,6 +1254,7 @@ __VMsgTypeEncode(VObject *pTypeObj, char *pType)
        int                     len;
        char*           pTemp = NULL;
        char*           szTypeValue = NULL;
+       char*           szTemp = NULL;
        int                     i;
        int                     enc = 0;
        char*           pEncode = NULL;
@@ -1268,21 +1276,27 @@ __VMsgTypeEncode(VObject *pTypeObj, char *pType)
        pTemp = __VMsgParamEncode(pTypeObj, &enc);
        if (pTemp != NULL) {
                len = strlen(pTemp);
-               if ((szTypeValue = (char *)realloc(szTypeValue, (total += len))) == NULL) {
+               if ((szTemp = (char *)realloc(szTypeValue, (total += len))) == NULL) {
                        VDATA_TRACE("__VMsgTypeEncode():realloc failed\n");
                        VFREE(pTemp);
-                       pTemp = NULL
-                       VDATA_TRACE_END;
+                       pTemp = NULL;
+                       VFREE(szTypeValue);
+                       VDATA_TRACE_END
                        return NULL;
+               } else {
+                       szTypeValue = szTemp;
                }
                g_strlcat(szTypeValue, pTemp, len);
                VFREE(pTemp);
                pTemp = NULL;
        }
 
-       if ((szTypeValue = (char *)realloc(szTypeValue, (total += 2))) == NULL) {
+       if ((szTemp = (char *)realloc(szTypeValue, (total += 2))) == NULL) {
+               VFREE(szTypeValue);
                VDATA_TRACE_END
                return NULL;
+       } else {
+               szTypeValue = szTemp;
        }
 
        g_strlcat(szTypeValue, ":", 2);
@@ -1369,21 +1383,27 @@ __VMsgTypeEncode(VObject *pTypeObj, char *pType)
                }
        }
 
-       if ((pRes = (char *)realloc(pRes, strlen(pRes) + 3)) == NULL) {
+       if ((szTemp = (char *)realloc(pRes, strlen(pRes) + 3)) == NULL) {
                VFREE(pEncode);
                VFREE(szTypeValue);
+               VFREE(pRes);
                VDATA_TRACE_END
                return NULL;
+       } else {
+               pRes = szTemp;
        }
        g_strlcat(pRes, "\r\n", strlen(pRes) + 2);
 
        len = strlen(pRes);
 
-       if ((szTypeValue = (char *)realloc(szTypeValue, (total += (len+3)))) == NULL) {
+       if ((szTemp = (char *)realloc(szTypeValue, (total += (len+3)))) == NULL) {
                VFREE(pEncode);
                VFREE(pRes);
+               VFREE(szTypeValue);
                VDATA_TRACE_END
                return NULL;
+       } else {
+               szTypeValue = szTemp;
        }
 
        g_strlcat(szTypeValue, pRes, total - 1);
@@ -1415,6 +1435,7 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
        int shift = 0;
        bool bSupported;
        char* szParam = NULL;
+       char* szTemp = NULL;
        VParam* pTemp = NULL;
        ValueObj*       pList = NULL;
 
@@ -1438,9 +1459,12 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
                bSupported = false;
 
                /** Expand szParam string. For appending.*/
-               if ((szParam = (char *)realloc(szParam, len += 15)) == NULL) {
+               if ((szTemp = (char *)realloc(szParam, len += 15)) == NULL) {
+                       VFREE(szParam);
                        VDATA_TRACE_END
                        return NULL;
+               } else {
+                       szParam = szTemp;
                }
 
                /** appending paramter name. */
@@ -1470,9 +1494,12 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
                        pList = pMsgCharsetList; bSupported = true;
                        break;
                default:
-                       if ((szParam = (char*)realloc(szParam, 5)) == NULL) {
+                       if ((szTemp = (char*)realloc(szParam, 5)) == NULL) {
+                               VFREE(szParam);
                                VDATA_TRACE_END
                                return NULL;
+                       } else {
+                               szParam = szTemp;
                        }
                        g_strlcat(szParam, "NONE", strlen("NONE"));
                }
@@ -1483,9 +1510,12 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
                        for (i = 0, sNum = 0x00000001; i < shift; i++) {
 
                                if (pList[pTemp->paramValue].flag & sNum) {
-                                       if ((szParam = (char *)realloc(szParam, (len += (strlen(pList[i].szName) + 2)))) == NULL) {
+                                       if ((szTemp = (char *)realloc(szParam, (len += (strlen(pList[i].szName) + 2)))) == NULL) {
+                                               VFREE(szParam);
                                                VDATA_TRACE_END
                                                return NULL;
+                                       } else {
+                                               szParam = szTemp;
                                        }
 
                                        g_strlcat(szParam, pList[i].szName, len);