Module: sip-router
Branch: master
Commit: 06e71ad96e8f13bafac1fa5d968538f98bd08df5
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=06e71ad…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Jan 31 23:08:02 2012 +0100
snmpstats: safe destroy in case of invalid startup
- some pointers were not intialized yet, but due to destroy of no-startup
they were accessed
- reported by Klaus Feichtinger
---
modules_k/snmpstats/interprocess_buffer.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/modules_k/snmpstats/interprocess_buffer.c
b/modules_k/snmpstats/interprocess_buffer.c
index c36b079..3ad7113 100644
--- a/modules_k/snmpstats/interprocess_buffer.c
+++ b/modules_k/snmpstats/interprocess_buffer.c
@@ -61,15 +61,15 @@
*
* 2) maps a given aor to a contact list.
*/
-hashSlot_t *hashTable;
+hashSlot_t *hashTable = NULL;
/*! All interprocess communication is stored between these two declarations. */
-interprocessBuffer_t *frontRegUserTableBuffer;
-interprocessBuffer_t *endRegUserTableBuffer;
+interprocessBuffer_t *frontRegUserTableBuffer = NULL;
+interprocessBuffer_t *endRegUserTableBuffer = NULL;
/*! This is to protect the potential racecondition in which a command is added to
* the buffer while it is being consumed */
-gen_lock_t *interprocessCBLock;
+gen_lock_t *interprocessCBLock = NULL;
/*!
* This function takes an element of the interprocess buffer passed to it, and
@@ -103,12 +103,23 @@ int initInterprocessBuffers(void)
* command was received while the interprocess buffer was being consumed.
*/
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;
+ }
lock_init(interprocessCBLock);
hashTable = createHashTable(HASH_SIZE);
if(hashTable == NULL)
{
LM_ERR("no more shared memory\n");
+ lock_destroy(interprocessCBLock);
+ lock_dealloc(interprocessCBLock);
shm_free(frontRegUserTableBuffer);
frontRegUserTableBuffer = NULL;
shm_free(endRegUserTableBuffer);
@@ -351,7 +362,9 @@ void freeInterprocessBuffer(void)
{
interprocessBuffer_t *currentBuffer, *previousBuffer;
- if (frontRegUserTableBuffer->next == NULL) {
+ if (frontRegUserTableBuffer==NULL
+ || frontRegUserTableBuffer->next == NULL
+ || endRegUserTableBuffer==NULL) {
LM_DBG("Nothing to clean\n");
return;
}