[Asterisk-code-review] chan ooh323: Fix cppcheck warnings (asterisk[15])

Joshua Colp asteriskteam at digium.com
Wed Apr 25 04:29:03 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8811 )

Change subject: chan_ooh323: Fix cppcheck warnings
......................................................................

chan_ooh323: Fix cppcheck warnings

Fix cppcheck warnings about redundant conditions and possible
null pointer usage

ASTERISK-27793 #close
Reported by: Ilya Shipitsin
Tested by: Ilya Shipitsin

Change-Id: I0b31933b062a23331dbac9a82b8bcfe345f406f6
---
M addons/chan_ooh323.c
M addons/ooh323c/src/context.c
M addons/ooh323c/src/memheap.c
M addons/ooh323c/src/ooCalls.c
M addons/ooh323c/src/ooCapability.c
M addons/ooh323c/src/ooGkClient.c
M addons/ooh323c/src/ooh245.c
M addons/ooh323c/src/ooq931.c
8 files changed, 17 insertions(+), 21 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/addons/chan_ooh323.c b/addons/chan_ooh323.c
index 278c587..8c5910d 100644
--- a/addons/chan_ooh323.c
+++ b/addons/chan_ooh323.c
@@ -5053,9 +5053,7 @@
 					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(p->owner),target_context);
 				}
 				p->faxdetected = 1;
-				if (dfr) {
-					ast_frfree(dfr);
-				}
+				ast_frfree(dfr);
 				return &ast_null_frame;
 			}
 		}
diff --git a/addons/ooh323c/src/context.c b/addons/ooh323c/src/context.c
index bc3db43..c1e2003 100644
--- a/addons/ooh323c/src/context.c
+++ b/addons/ooh323c/src/context.c
@@ -164,6 +164,7 @@
          /* ASN1CRTFREE0 (pctxt); */
 	 ast_free(pctxt);
          pctxt = 0;
+         return (pctxt);
       }
       pctxt->flags |= ASN1DYNCTXT;
    }
diff --git a/addons/ooh323c/src/memheap.c b/addons/ooh323c/src/memheap.c
index 4bcbd7a..4020261 100644
--- a/addons/ooh323c/src/memheap.c
+++ b/addons/ooh323c/src/memheap.c
@@ -623,7 +623,7 @@
             }
          }
       }
-      if (!ISLAST (pElem) && ISFREE (GETNEXT (pElem))) {
+      if (pElem && !ISLAST (pElem) && ISFREE (GETNEXT (pElem))) {
          OSMemElemDescr* nextelem_p = GETNEXT (pElem);
 
          /* +1 because the OSMemElemDescr has size ONE unit (8 bytes) */
@@ -638,7 +638,7 @@
       }
 
       /* correct the prevOff field of next element */
-      if (!ISLAST (pElem)) {
+      if (pElem && !ISLAST (pElem)) {
          OSMemElemDescr* nextelem_p = GETNEXT (pElem);
          pElem_prevOff (nextelem_p) = QOFFSETOF (nextelem_p, pElem);
       }
@@ -686,7 +686,7 @@
    }
 
    pNextElem = GETNEXT (pNewElem);
-   if (ISFREE (pNextElem)) {
+   if (pNextElem && ISFREE (pNextElem)) {
 
       /* if the next elem is free, then unite them together */
 
@@ -820,7 +820,7 @@
             /* look for free element after pElem */
 
             pNextElem = GETNEXT (pElem);
-            if (ISFREE (pNextElem)) {
+            if (pNextElem && ISFREE (pNextElem)) {
                /* +1 'cos sizeof (OSMemElemDescr) == 1 unit */
                sumSize += pElem_nunits (pNextElem) + 1;
                freeMem++;
@@ -1062,7 +1062,7 @@
 void memHeapRelease (void** ppvMemHeap)
 {
    OSMemHeap** ppMemHeap = (OSMemHeap**)ppvMemHeap;
-   OSMemHeap* pMemHeap = *ppMemHeap;
+   OSMemHeap* pMemHeap;
 
    if (ppMemHeap != 0 && *ppMemHeap != 0 && --(*ppMemHeap)->refCnt == 0) {
       OSMemLink* pMemLink, *pMemLink2;
@@ -1080,6 +1080,7 @@
       }
 
       if ((*ppMemHeap)->flags & RT_MH_FREEHEAPDESC) {
+         pMemHeap = *ppMemHeap;
          ast_mutex_destroy(&pMemHeap->pLock);
          ast_free(*ppMemHeap);
       }
diff --git a/addons/ooh323c/src/ooCalls.c b/addons/ooh323c/src/ooCalls.c
index 3097c6d..15ab325 100644
--- a/addons/ooh323c/src/ooCalls.c
+++ b/addons/ooh323c/src/ooCalls.c
@@ -805,8 +805,7 @@
 
    if(!call)
    {
-      OOTRACEERR3("Error:Invalid 'call' param for ooAddMediaInfo.(%s, %s)\n",
-                   call->callType, call->callToken);
+      OOTRACEERR1("Error:Invalid 'call' param for ooAddMediaInfo.\n");
       return OO_FAILED;
    }
    newMediaInfo = (OOMediaInfo*) memAlloc(call->pctxt, sizeof(OOMediaInfo));
diff --git a/addons/ooh323c/src/ooCapability.c b/addons/ooh323c/src/ooCapability.c
index 7314783..0796c46 100644
--- a/addons/ooh323c/src/ooCapability.c
+++ b/addons/ooh323c/src/ooCapability.c
@@ -62,8 +62,6 @@
       /*Dynamic RTP payload type range is from 96 - 127 */
       if(dynamicRTPPayloadType >= 96 && dynamicRTPPayloadType <= 127)
         gcDynamicRTPPayloadType = dynamicRTPPayloadType;
-      else
-        call->dtmfcodec = dynamicRTPPayloadType;
    }
    else{
       call->dtmfmode |= OO_CAP_DTMF_CISCO;
@@ -623,8 +621,7 @@
    else pctxt = call->pctxt;
 
    epCap = (ooH323EpCapability*)memAllocZ(pctxt, sizeof(ooH323EpCapability));
-   params = (OOCapParams*) memAlloc(pctxt, sizeof(OOCapParams));
-   memset(params, 0 , sizeof(OOCapParams));
+   params = (OOCapParams*) memAllocZ(pctxt, sizeof(OOCapParams));
    if(!epCap || !params)
    {
       OOTRACEERR1("ERROR: Memory - ooCapabilityAddT38Capability - "
@@ -808,8 +805,7 @@
       }
       memset(pATECap, 0, sizeof(H245AudioTelephonyEventCapability));
       pATECap->dynamicRTPPayloadType = dtmfcodec;
-      events = (char*)memAlloc(pctxt, strlen("0-16")+1);
-      memset(events, 0, strlen("0-16")+1);
+      events = (char*)memAllocZ(pctxt, strlen("0-16")+1);
       if(!events)
       {
          OOTRACEERR1("Error:Memory - ooCapabilityCreateDTMFCapability - events\n");
diff --git a/addons/ooh323c/src/ooGkClient.c b/addons/ooh323c/src/ooGkClient.c
index a307f4e..0168ee7 100644
--- a/addons/ooh323c/src/ooGkClient.c
+++ b/addons/ooh323c/src/ooGkClient.c
@@ -2332,9 +2332,8 @@
    pIRR->m.perCallInfoPresent = TRUE;
 
    perCallInfo =
-    (H225InfoRequestResponse_perCallInfo_element *)memAlloc(pctxt,
+    (H225InfoRequestResponse_perCallInfo_element *)memAllocZ(pctxt,
      sizeof(H225InfoRequestResponse_perCallInfo_element));
-   memset(perCallInfo, 0, sizeof(H225InfoRequestResponse_perCallInfo_element));
 
    if(!perCallInfo)
    {
diff --git a/addons/ooh323c/src/ooh245.c b/addons/ooh323c/src/ooh245.c
index adff917..fe8ff28 100644
--- a/addons/ooh323c/src/ooh245.c
+++ b/addons/ooh323c/src/ooh245.c
@@ -356,7 +356,6 @@
    /* pctxt = &gH323ep.msgctxt; */
    pctxt = call->msgctxt;
    ph245msg->msgType = OOTerminalCapabilitySet;
-   memset(request, 0, sizeof(H245RequestMessage));
    if(request == NULL)
    {
       OOTRACEERR3("ERROR: No memory allocated for request message (%s, %s)\n",
@@ -364,6 +363,7 @@
       return OO_FAILED;
    }
 
+   memset(request, 0, sizeof(H245RequestMessage));
    request->t = T_H245RequestMessage_terminalCapabilitySet;
    request->u.terminalCapabilitySet = (H245TerminalCapabilitySet*)
                   memAlloc(pctxt, sizeof(H245TerminalCapabilitySet));
diff --git a/addons/ooh323c/src/ooq931.c b/addons/ooh323c/src/ooq931.c
index 1ca361c..01a8e4a 100644
--- a/addons/ooh323c/src/ooq931.c
+++ b/addons/ooh323c/src/ooq931.c
@@ -2439,8 +2439,10 @@
       alias = call->pCallFwdData->aliases;
       while(alias)
       {
-         pNewAlias = (ooAliases*) memAlloc(pctxt, sizeof(ooAliases));
-         pNewAlias->value = (char*) memAlloc(pctxt, strlen(alias->value)+1);
+         pNewAlias = (ooAliases*) memAllocZ(pctxt, sizeof(ooAliases));
+         if (pNewAlias) {
+            pNewAlias->value = (char*) memAllocZ(pctxt, strlen(alias->value)+1);
+         }
          if(!pNewAlias || !pNewAlias->value)
          {
             OOTRACEERR3("Error:Memory - ooH323HandleCallFwdRequest - "

-- 
To view, visit https://gerrit.asterisk.org/8811
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I0b31933b062a23331dbac9a82b8bcfe345f406f6
Gerrit-Change-Number: 8811
Gerrit-PatchSet: 1
Gerrit-Owner: Alexander Anikin <may213 at yandex.ru>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180425/d9e9bb45/attachment-0001.html>


More information about the asterisk-code-review mailing list