[asterisk-commits] may: branch may/chan_ooh323_evo r338506 - /team/may/chan_ooh323_evo/addons/oo...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 29 14:19:13 CDT 2011


Author: may
Date: Thu Sep 29 14:19:08 2011
New Revision: 338506

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=338506
Log:
split one permanent memory allocation context to three ctxts 
for periodically operations (GRQ,RRQ). New contexts are
sendctxt, recvctxt, printctxt and they are created and deleted
every transaction.
Adjust some buffers for encoding/decoding procs.

Main thing of these is to resolve memory leak in gatekeeper client code.
Now there is no leak but some memory corruption found (i don't known
reason now may be ooh323 isn't this).

Modified:
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.c
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.h
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooasn1.h
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323.c
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323ep.c
    team/may/chan_ooh323_evo/addons/ooh323c/src/ooq931.c

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.c?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.c (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.c Thu Sep 29 14:19:08 2011
@@ -48,6 +48,12 @@
    6, { 0, 0, 8, 2250, 0, 4 }
 };
 
+static OOCTXT* ooSendPCTXT = NULL;
+static OOCTXT* ooRecvPCTXT = NULL;
+static OOCTXT* ooPrintPCTXT = NULL;
+
+
+
 int ooGkClientInit(enum RasGatekeeperMode eGkMode,
               char *szGkAddr, int iGkPort )
 {
@@ -365,7 +371,7 @@
 
 int ooGkClientReceive(ooGkClient *pGkClient)
 {
-   ASN1OCTET recvBuf[1024];
+   ASN1OCTET recvBuf[2048];
    int recvLen;
    char remoteHost[32];
    int iFromPort=0;
@@ -374,9 +380,16 @@
    int iRet=OO_OK;
    
    ast_mutex_lock(&pGkClient->Lock);
-   pctxt = &pGkClient->msgCtxt;
-
-   recvLen = ooSocketRecvFrom(pGkClient->rasSocket, recvBuf, 1024, remoteHost,
+   /* pctxt = &pGkClient->msgCtxt; */
+
+   if (ooRecvPCTXT != NULL) {
+   	freeContext(ooRecvPCTXT);
+	free(ooRecvPCTXT);
+   }
+   ooRecvPCTXT = newContext();
+   pctxt = ooRecvPCTXT;
+
+   recvLen = ooSocketRecvFrom(pGkClient->rasSocket, recvBuf, 2048, remoteHost,
                               32, &iFromPort);
    if(recvLen <0)
    {
@@ -433,7 +446,7 @@
          OOTRACEERR1("Error: Failed to handle received RAS message\n");
          pGkClient->state = GkClientFailed;
       }
-      memReset(pctxt);
+      /* memReset(pctxt); */
    }
    else{
       OOTRACEERR1("ERROR:Failed to decode received RAS message- ignoring"
@@ -538,35 +551,42 @@
 void ooGkClientPrintMessage
    (ooGkClient *pGkClient, ASN1OCTET *msg, ASN1UINT len)
 {
-   OOCTXT ctxt;
+   OOCTXT* ctxt = NULL;
    H225RasMessage rasMsg;
    int ret; 
 
-   initContext(&ctxt);
-   setPERBuffer(&ctxt, msg, len, TRUE);
+   if (ooPrintPCTXT != NULL) {
+   	freeContext(ooPrintPCTXT);
+	free(ooPrintPCTXT);
+   }
+   ooPrintPCTXT = newContext();
+   ctxt = ooPrintPCTXT;
+
+   setPERBuffer(ctxt, msg, len, TRUE);
    initializePrintHandler(&printHandler, "Sending RAS Message");
-   setEventHandler(&ctxt, &printHandler);
-
-   ret = asn1PD_H225RasMessage(&ctxt, &rasMsg);
+   setEventHandler(ctxt, &printHandler);
+
+   ret = asn1PD_H225RasMessage(ctxt, &rasMsg);
    if(ret != ASN_OK)
    {
       OOTRACEERR1("Error: Failed to decode RAS message\n");
    }
    finishPrint();
-   freeContext(&ctxt);
 }
 #endif
 /**
  * Encode and send RAS message.
  */
 
-int ooGkClientSendMsg(ooGkClient *pGkClient, H225RasMessage *pRasMsg)
+int ooGkClientSendMsg(ooGkClient *pGkClient, H225RasMessage *pRasMsg, OOCTXT *pctxt)
 {
    ASN1OCTET msgBuf[MAXMSGLEN];
    ASN1OCTET *msgPtr=NULL;
    int  iLen;
 
-   OOCTXT *pctxt = &pGkClient->msgCtxt;
+   /* OOCTXT *pctxt = &pGkClient->msgCtxt; */
+   if (!pctxt)
+	pctxt = &pGkClient->msgCtxt;
 
    setPERBuffer( pctxt, msgBuf, MAXMSGLEN, TRUE );
    if ( ASN_OK == asn1PE_H225RasMessage(pctxt, pRasMsg) )
@@ -617,10 +637,24 @@
    H225RasMessage *pRasMsg=NULL;
    H225GatekeeperRequest *pGkReq=NULL;
    H225TransportAddress_ipAddress *pRasAddress;
-   OOCTXT *pctxt = &pGkClient->msgCtxt;
+   OOCTXT *pctxt = NULL;
    ooGkClientTimerCb *cbData=NULL;
 
    ast_mutex_lock(&pGkClient->Lock);
+
+   if (ooSendPCTXT != NULL) {
+   	freeContext(ooSendPCTXT);
+	free(ooSendPCTXT);
+   }
+   ooSendPCTXT = newContext();
+   pctxt = ooSendPCTXT;
+
+   if (!pctxt) {
+      OOTRACEERR1("Error:Memory allocation for GRQ context failed\n");
+      pGkClient->state = GkClientFailed;
+      ast_mutex_unlock(&pGkClient->Lock);
+      return OO_FAILED;
+   }
 
    /* Allocate memory for RAS message */
    pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage));
@@ -686,7 +720,7 @@
 
 
    pGkReq->m.endpointAliasPresent=TRUE;
-   if(OO_OK != ooPopulateAliasList(&pGkClient->msgCtxt, gH323ep.aliases, 
+   if(OO_OK != ooPopulateAliasList(pctxt, gH323ep.aliases, 
                                       &pGkReq->endpointAlias, 0))
    {
       OOTRACEERR1("Error Failed to fill alias information for GRQ message\n");
@@ -695,7 +729,7 @@
       ast_mutex_unlock(&pGkClient->Lock);
       return OO_FAILED;
    }
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error: Failed to send GRQ message\n");
@@ -859,7 +893,6 @@
          memFreePtr(&pGkClient->ctxt, pTimer->cbData);
          ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer);
          OOTRACEDBGA1("Deleted GRQ Timer.\n");
-         break;
       }
    }
 
@@ -881,7 +914,7 @@
    int iRet;
    H225RasMessage *pRasMsg=NULL;
    H225RegistrationRequest *pRegReq=NULL;
-   OOCTXT *pctxt=NULL;
+   OOCTXT *pctxt = NULL;
    H225TransportAddress *pTransportAddress=NULL;
    H225TransportAddress_ipAddress *pIpAddress=NULL;
    ooGkClientTimerCb *cbData =NULL;
@@ -890,7 +923,18 @@
 
    ast_mutex_lock(&pGkClient->Lock);
 
-   pctxt = &pGkClient->msgCtxt;
+   if (ooSendPCTXT != NULL) {
+   	freeContext(ooSendPCTXT);
+	free(ooSendPCTXT);
+   }
+   ooSendPCTXT = newContext();
+   pctxt = ooSendPCTXT;
+
+   if (!pctxt) {
+      pGkClient->state = GkClientFailed;
+      ast_mutex_unlock(&pGkClient->Lock);
+      return OO_FAILED;
+   }
 
    pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage));
    if(!pRasMsg)
@@ -912,6 +956,7 @@
       return OO_FAILED;
    }
    memset(pRegReq, 0, sizeof(H225RegistrationRequest));
+
    pRasMsg->t = T_H225RasMessage_registrationRequest;
    pRasMsg->u.registrationRequest = pRegReq;
    
@@ -1083,7 +1128,7 @@
    pRegReq->m.timeToLivePresent = TRUE;
    pRegReq->timeToLive = pGkClient->regTimeout;
 
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error: Failed to send RRQ message\n");
@@ -1092,6 +1137,7 @@
       ast_mutex_unlock(&pGkClient->Lock);
       return OO_FAILED;
    }
+
    OOTRACEINFO1("Sent RRQ message \n");
    /* Start RRQ Timer */
    cbData = (ooGkClientTimerCb*) memAlloc
@@ -1486,7 +1532,7 @@
    }
 
   
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error:Failed to send UnregistrationRequest message\n");
@@ -1590,7 +1636,7 @@
    
    pUCF->requestSeqNum = reqNo;
    
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error:Failed to send UnregistrationConfirm message\n");
@@ -1865,7 +1911,7 @@
       }
    }
    
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error:Failed to send AdmissionRequest message\n");
@@ -2379,7 +2425,7 @@
    dListAppend(pctxt, &pIRR->perCallInfo,
                                        (void*)perCallInfo);
 
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error:Failed to send IRR message\n");
@@ -2533,7 +2579,7 @@
     pDRQ->usageInformation.endTime = time(NULL);
    pDRQ->m.usageInformationPresent = TRUE;
 
-   iRet = ooGkClientSendMsg(pGkClient, pRasMsg);
+   iRet = ooGkClientSendMsg(pGkClient, pRasMsg, pctxt);
    if(iRet != OO_OK)
    {
       OOTRACEERR1("Error: Failed to send DRQ message\n");

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.h?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.h (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooGkClient.h Thu Sep 29 14:19:08 2011
@@ -323,7 +323,7 @@
  *
  * @return            OO_OK, on success. OO_FAILED, otherwise. 
  */
-EXTERN int ooGkClientSendMsg(ooGkClient *pGkClient, H225RasMessage *pRasMsg);
+EXTERN int ooGkClientSendMsg(ooGkClient *pGkClient, H225RasMessage *pRasMsg, OOCTXT *pctxt);
 
 
 /**

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooasn1.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooasn1.h?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooasn1.h (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooasn1.h Thu Sep 29 14:19:08 2011
@@ -139,7 +139,7 @@
 #define ASN_K_MAXENUM   100     /* maximum enum values in an enum type  */
 #define ASN_K_MAXERRP   5       /* maximum error parameters             */
 #define ASN_K_MAXERRSTK 8       /* maximum levels on error ctxt stack   */
-#define ASN_K_ENCBUFSIZ 2*1024 /* dynamic encode buffer extent size    */
+#define ASN_K_ENCBUFSIZ 8*1024 /* dynamic encode buffer extent size    */
 #define ASN_K_MEMBUFSEG 1024    /* memory buffer extent size            */
 
 /* Canonical character set definitions */

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323.c?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323.c (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323.c Thu Sep 29 14:19:08 2011
@@ -2356,7 +2356,7 @@
 	  pAlias = pAlias->next;
 	  continue;
 	 }
-         pAliasEntry = (H225AliasAddress*)memAlloc(pctxt, 
+         pAliasEntry = (H225AliasAddress*)memAllocZ(pctxt, 
                                                      sizeof(H225AliasAddress));
          if(!pAliasEntry)
          {
@@ -2372,7 +2372,7 @@
          {
             case T_H225AliasAddress_dialedDigits:
              pAliasEntry->t = T_H225AliasAddress_dialedDigits;
-             pAliasEntry->u.dialedDigits = (ASN1IA5String)memAlloc(pctxt,
+             pAliasEntry->u.dialedDigits = (ASN1IA5String)memAllocZ(pctxt,
                                                      strlen(pAlias->value)+1);
              if(!pAliasEntry->u.dialedDigits)
              {
@@ -2402,7 +2402,7 @@
             break;
          case T_H225AliasAddress_url_ID:
             pAliasEntry->t = T_H225AliasAddress_url_ID;
-            pAliasEntry->u.url_ID = (ASN1IA5String)memAlloc(pctxt, 
+            pAliasEntry->u.url_ID = (ASN1IA5String)memAllocZ(pctxt, 
                                                      strlen(pAlias->value)+1);
             if(!pAliasEntry->u.url_ID)
             {
@@ -2415,7 +2415,7 @@
             break;
          case T_H225AliasAddress_email_ID:
             pAliasEntry->t = T_H225AliasAddress_email_ID;
-            pAliasEntry->u.email_ID = (ASN1IA5String)memAlloc(pctxt, 
+            pAliasEntry->u.email_ID = (ASN1IA5String)memAllocZ(pctxt, 
                                                      strlen(pAlias->value)+1);
             if(!pAliasEntry->u.email_ID)
             {

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323ep.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323ep.c?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323ep.c (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooh323ep.c Thu Sep 29 14:19:08 2011
@@ -202,7 +202,7 @@
 int ooH323EpAddAliasDialedDigits(const char* dialedDigits)
 {
    ooAliases * psNewAlias=NULL;
-   psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases));
+   psNewAlias = (ooAliases*)memAllocZ(&gH323ep.ctxt, sizeof(ooAliases));
    if(!psNewAlias)
    {
       OOTRACEERR1("Error: Failed to allocate memory for new DialedDigits "
@@ -211,7 +211,7 @@
    }
    psNewAlias->type = T_H225AliasAddress_dialedDigits;
    psNewAlias->registered = FALSE;
-   psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(dialedDigits)+1);
+   psNewAlias->value = (char*) memAllocZ(&gH323ep.ctxt, strlen(dialedDigits)+1);
    if(!psNewAlias->value)
    {
       OOTRACEERR1("Error: Failed to allocate memory for the new DialedDigits"

Modified: team/may/chan_ooh323_evo/addons/ooh323c/src/ooq931.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_evo/addons/ooh323c/src/ooq931.c?view=diff&rev=338506&r1=338505&r2=338506
==============================================================================
--- team/may/chan_ooh323_evo/addons/ooh323c/src/ooq931.c (original)
+++ team/may/chan_ooh323_evo/addons/ooh323c/src/ooq931.c Thu Sep 29 14:19:08 2011
@@ -512,7 +512,7 @@
 
 int ooEncodeUUIE(OOCTXT* pctxt, Q931Message *q931msg)
 {
-   ASN1OCTET msgbuf[1024];
+   ASN1OCTET msgbuf[ASN_K_ENCBUFSIZ];
    ASN1OCTET * msgptr=NULL;
    int  len;
    ASN1BOOL aligned = TRUE;




More information about the asterisk-commits mailing list