Module: sip-router
Branch: master
Commit: 49837c37aea72c1e4f0cc3290382c0adbf72e3f8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=49837c3…
Author: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Date: Tue Nov 2 11:45:15 2010 +0200
trie API Fixed dtrie_insert OOM handling, where assert() was wrongfully used
Now the function behaves as expected, freeing previous allocated resources, logging the
OOM condition , and returning -1
---
lib/trie/dtrie.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/trie/dtrie.c b/lib/trie/dtrie.c
index 9965263..90cb52f 100644
--- a/lib/trie/dtrie.c
+++ b/lib/trie/dtrie.c
@@ -39,8 +39,6 @@
#include "dtrie.h"
-#include <assert.h>
-
#include "../../dprint.h"
#include "../../mem/shm_mem.h"
#include "../../mem/mem.h"
@@ -142,12 +140,20 @@ int dtrie_insert(struct dtrie_node_t *root, const char *number,
const unsigned i
if (node->child[digit] == NULL) {
node->child[digit] = shm_malloc(sizeof(struct dtrie_node_t));
- assert(node->child[digit] != NULL);
+ if(node->child[digit] == NULL ){
+ SHM_MEM_ERROR;
+ return -1;
+ }
+
LM_DBG("allocate %lu bytes for node at %p\n", (long unsigned)sizeof(struct
dtrie_node_t), node->child[digit]);
memset(node->child[digit], 0, sizeof(struct dtrie_node_t));
node->child[digit]->child = shm_malloc(sizeof(struct dtrie_node_t *) *
branches);
- assert(node->child[digit]->child != NULL);
+ if(node->child[digit]->child == NULL){
+ SHM_MEM_ERROR;
+ shm_free(node->child[digit]);
+ return -1;
+ }
LM_DBG("allocate %lu bytes for %d root children pointer at %p\n",
(long unsigned)sizeof(struct dtrie_node_t *) * branches,
branches, node->child[digit]->child);