Skip to content

Commit

Permalink
snmpstats Improve formatting, add comments on InterProcessBuffer grow…
Browse files Browse the repository at this point in the history
…ing forever
  • Loading branch information
oej committed May 24, 2016
1 parent bd09692 commit aa73c87
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
64 changes: 32 additions & 32 deletions modules/snmpstats/interprocess_buffer.c
Expand Up @@ -85,11 +85,11 @@ int initInterprocessBuffers(void)
frontRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t));
endRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t));

if(frontRegUserTableBuffer == NULL || endRegUserTableBuffer == NULL)
{
LM_ERR("no more shared memory\n");
return -1;
}
if(frontRegUserTableBuffer == NULL || endRegUserTableBuffer == NULL)
{
LM_ERR("no more shared memory\n");
return -1;
}

memset(frontRegUserTableBuffer, 0x00, sizeof(interprocessBuffer_t));
memset(endRegUserTableBuffer, 0x00, sizeof(interprocessBuffer_t));
Expand All @@ -101,27 +101,27 @@ int initInterprocessBuffers(void)
interprocessCBLock = lock_alloc();
if(interprocessCBLock==NULL)
{
LM_ERR("cannot allocate the lock\n");
shm_free(frontRegUserTableBuffer);
frontRegUserTableBuffer = NULL;
shm_free(endRegUserTableBuffer);
endRegUserTableBuffer = NULL;
return -1;
LM_ERR("cannot allocate the lock\n");
shm_free(frontRegUserTableBuffer);
frontRegUserTableBuffer = NULL;
shm_free(endRegUserTableBuffer);
endRegUserTableBuffer = NULL;
return -1;
}
lock_init(interprocessCBLock);

hashTable = createHashTable(HASH_SIZE);
if(hashTable == NULL)
{
LM_ERR("no more shared memory\n");
if(hashTable == NULL)
{
LM_ERR("no more shared memory\n");
lock_destroy(interprocessCBLock);
lock_dealloc(interprocessCBLock);
shm_free(frontRegUserTableBuffer);
frontRegUserTableBuffer = NULL;
shm_free(endRegUserTableBuffer);
endRegUserTableBuffer = NULL;
return -1;
}
shm_free(frontRegUserTableBuffer);
frontRegUserTableBuffer = NULL;
shm_free(endRegUserTableBuffer);
endRegUserTableBuffer = NULL;
return -1;
}

return 1;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param)

/* This is the first element to be added. */
if (frontRegUserTableBuffer->next == NULL) {
frontRegUserTableBuffer->next = currentBufferElement;
frontRegUserTableBuffer->next = currentBufferElement;
} else {
endRegUserTableBuffer->next->next = currentBufferElement;
}
Expand Down Expand Up @@ -356,12 +356,12 @@ static void executeInterprocessBufferCmd(interprocessBuffer_t *currentBuffer)

void freeInterprocessBuffer(void)
{
interprocessBuffer_t *currentBuffer, *previousBuffer;
interprocessBuffer_t *currentBuffer, *previousBuffer;

if (frontRegUserTableBuffer==NULL
|| frontRegUserTableBuffer->next == NULL
|| endRegUserTableBuffer==NULL) {
LM_DBG("Nothing to clean\n");
LM_DBG("Nothing to clean\n");
return;
}

Expand All @@ -373,18 +373,18 @@ void freeInterprocessBuffer(void)

while (currentBuffer != NULL) {

previousBuffer = currentBuffer;
currentBuffer = currentBuffer->next;
shm_free(previousBuffer->stringName);
shm_free(previousBuffer->stringContact);
shm_free(previousBuffer);
previousBuffer = currentBuffer;
currentBuffer = currentBuffer->next;
shm_free(previousBuffer->stringName);
shm_free(previousBuffer->stringContact);
shm_free(previousBuffer);

}

if(frontRegUserTableBuffer)
shm_free(frontRegUserTableBuffer);
if(frontRegUserTableBuffer)
shm_free(frontRegUserTableBuffer);

if(endRegUserTableBuffer)
shm_free(endRegUserTableBuffer);
if(endRegUserTableBuffer)
shm_free(endRegUserTableBuffer);

}
6 changes: 0 additions & 6 deletions modules/snmpstats/snmpObjects.c
Expand Up @@ -20,12 +20,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* History:
* --------
* 2006-11-23 initial version (jmagder)
* 2007-02-16 Moved all OID registrations from the experimental branch to
* Kamailio's IANA assigned enterprise branch. (jmagder)
*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf,v 1.9 2005/01/07 09:37:18 dts12 Exp $
*
Expand Down
8 changes: 4 additions & 4 deletions modules/snmpstats/snmpSIPContactTable.c
Expand Up @@ -20,10 +20,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* History:
* --------
* 2006-11-23 initial version (jmagder)
*
* Note: this file originally auto-generated by mib2c using
* mib2c.array-user.conf
*
Expand All @@ -48,6 +44,10 @@
* the interprocess buffer with consumeInterprocessBuffer(). The function
* will add/delete rows to the tables, and then service the SNMP request.
*
* 4) If the SNMP request is not received, the InterProcessBuffer keeps growing
* until end of time. This is not good. A timer callback or something else is
* needed to process it.
*
* Notes:
*
* - The interprocess buffer was necessary, because NetSNMP's containers can be
Expand Down

0 comments on commit aa73c87

Please sign in to comment.