Final fix memleaks in GkClient codes, same for Timer codes.
authorAlexandr Anikin <may@telecom-service.ru>
Fri, 4 Nov 2011 19:50:10 +0000 (19:50 +0000)
committerAlexandr Anikin <may@telecom-service.ru>
Fri, 4 Nov 2011 19:50:10 +0000 (19:50 +0000)
(these memleaks stop development of gk codes, now i can continue)
Fix printHandler 'Unbalanced Structure' issues with locking printHandler
data for single thread.
........

Merged revisions 343281 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 343445 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@343448 65c4cc65-6c06-0410-ace0-fbb531ad65f3

addons/ooh323c/src/dlist.c
addons/ooh323c/src/dlist.h
addons/ooh323c/src/ooGkClient.c
addons/ooh323c/src/ooTimer.c
addons/ooh323c/src/ooq931.c
addons/ooh323c/src/printHandler.c

index 6e110e1..71dd9ee 100644 (file)
@@ -135,7 +135,7 @@ void dListRemove (DList* pList, DListNode* node)
    pList->count--;
 }
 
-void dListFindAndRemove(DList* pList, void *data)
+void dListFindAndRemove(struct OOCTXT* pctxt, DList* pList, void *data)
 {
    DListNode *pNode, *pNextNode;
    for(pNode = pList->head; pNode !=0; pNode = pNextNode){
@@ -143,8 +143,10 @@ void dListFindAndRemove(DList* pList, void *data)
       if(pNode->data == data) /* pointer comparison*/
          break;
    }
-   if(pNode)
+   if(pNode) {
       dListRemove(pList, pNode);
+      memFreePtr(pctxt, pNode);
+   }
 }
     
 DListNode* dListFindByIndex (DList* pList, int index) 
index 79663d9..34a73c8 100644 (file)
@@ -192,7 +192,7 @@ EXTERN DListNode* dListInsertAfter
  *                     already be in the linked list structure.
  */
 EXTERN void  dListRemove (DList* pList, DListNode* node);
-void dListFindAndRemove(DList* pList, void* data);
+EXTERN void dListFindAndRemove(struct OOCTXT* pctxt, DList* pList, void* data);
 
 /** 
  * @}
index cfc7f33..dff3e75 100644 (file)
@@ -365,7 +365,7 @@ void ooGkClientFillVendor
 
 int ooGkClientReceive(ooGkClient *pGkClient)
 {
-   ASN1OCTET recvBuf[1024];
+   ASN1OCTET recvBuf[ASN_K_ENCBUFSIZ];
    int recvLen;
    char remoteHost[32];
    int iFromPort=0;
@@ -376,7 +376,7 @@ int ooGkClientReceive(ooGkClient *pGkClient)
    ast_mutex_lock(&pGkClient->Lock);
    pctxt = &pGkClient->msgCtxt;
 
-   recvLen = ooSocketRecvFrom(pGkClient->rasSocket, recvBuf, 1024, remoteHost,
+   recvLen = ooSocketRecvFrom(pGkClient->rasSocket, recvBuf, 2048, remoteHost,
                               32, &iFromPort);
    if(recvLen <0)
    {
@@ -859,7 +859,6 @@ int ooGkClientHandleGatekeeperConfirm
          memFreePtr(&pGkClient->ctxt, pTimer->cbData);
          ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer);
          OOTRACEDBGA1("Deleted GRQ Timer.\n");
-         break;
       }
    }
 
@@ -1064,7 +1063,7 @@ int ooGkClientSendRRQ(ooGkClient *pGkClient, ASN1BOOL keepAlive)
          allocate storage for endpoint-identifier, and populate it from what the
          GK told us from the previous RCF. Only allocate on the first pass thru here */
       pRegReq->endpointIdentifier.data = 
-           (ASN116BITCHAR*)memAlloc(pctxt, pGkClient->gkId.nchars*sizeof(ASN116BITCHAR));
+           (ASN116BITCHAR*)memAlloc(pctxt, pGkClient->endpointId.nchars*sizeof(ASN116BITCHAR));
       if (pRegReq->endpointIdentifier.data) {
          pRegReq->endpointIdentifier.nchars = pGkClient->endpointId.nchars;
          pRegReq->m.endpointIdentifierPresent = TRUE;
@@ -1137,6 +1136,8 @@ int ooGkClientHandleRegistrationConfirm
    ooGkClientTimerCb *cbData;
    ASN1UINT regTTL=0;
    /* Extract Endpoint Id */
+   if (pGkClient->endpointId.data)
+       memFreePtr(&pGkClient->ctxt, pGkClient->endpointId.data);
    pGkClient->endpointId.nchars = 
                               pRegistrationConfirm->endpointIdentifier.nchars;
    pGkClient->endpointId.data = (ASN116BITCHAR*)memAlloc(&pGkClient->ctxt,
@@ -1289,7 +1290,6 @@ int ooGkClientHandleRegistrationReject
          memFreePtr(&pGkClient->ctxt, pTimer->cbData);
          ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer);
          OOTRACEDBGA1("Deleted RRQ Timer.\n");
-         break;
       }
    }
 
index 9e7f722..ad5f37f 100644 (file)
@@ -79,7 +79,7 @@ void ooTimerComputeExpireTime (OOTimer* pTimer)
 
 void ooTimerDelete (OOCTXT* pctxt, DList *pList, OOTimer* pTimer)
 {
-   dListFindAndRemove (pList, pTimer);
+   dListFindAndRemove (pctxt, pList, pTimer);
    memFreePtr (pctxt, pTimer);
 }
 
@@ -115,7 +115,7 @@ void ooTimerFireExpired (OOCTXT* pctxt, DList *pList)
 
          stat = (*pTimer->timeoutCB)(pTimer->cbData);
 
-         if (0 != stat || !pTimer->reRegister) {
+         if (!pTimer->reRegister) {
             ooTimerDelete (pctxt, pList, pTimer);
          }
       }
@@ -175,7 +175,7 @@ struct timeval* ooTimerNextTimeout (DList *pList, struct timeval* ptimeout)
 void ooTimerReset (OOCTXT* pctxt, DList *pList, OOTimer* pTimer)
 {
    if (pTimer->reRegister) {
-      dListFindAndRemove (pList, pTimer);
+      dListFindAndRemove (pctxt, pList, pTimer);
       ooTimerComputeExpireTime (pTimer);
       ooTimerInsertEntry (pctxt, pList, pTimer);
    }
index 9fe6612..58befa8 100644 (file)
@@ -512,7 +512,7 @@ int ooFreeQ931Message(OOCTXT* pctxt, Q931Message *q931Msg)
 
 int ooEncodeUUIE(OOCTXT* pctxt, Q931Message *q931msg)
 {
-   ASN1OCTET msgbuf[1024];
+   ASN1OCTET msgbuf[ASN_K_ENCBUFSIZ];
    ASN1OCTET * msgptr=NULL;
    int  len;
    ASN1BOOL aligned = TRUE;
index abb4d4f..3931169 100644 (file)
@@ -30,6 +30,7 @@
 #include "ootrace.h"
 
 EventHandler printHandler;
+AST_MUTEX_DEFINE_STATIC(printlock);
 
 static const char* pVarName;
 static int gIndentSpaces;
@@ -60,6 +61,7 @@ void initializePrintHandler(EventHandler *printHandler, char * varname)
    printHandler->enumValue = &printEnumValue;
    printHandler->openTypeValue = &printOpenTypeValue;
    pVarName = varname;
+   ast_mutex_lock(&printlock);
    OOTRACEDBGB2("%s = {\n", pVarName);
    gIndentSpaces += 3;
 
@@ -72,6 +74,8 @@ void finishPrint()
    if (gIndentSpaces != 0) {
       OOTRACEDBGB1 ("ERROR: unbalanced structure\n");
    }
+   gIndentSpaces = 0;
+   ast_mutex_unlock(&printlock);
 }
 
 void indent ()