Quellcode durchsuchen

dtrie: Set child to NULL when run out of SHM

The stop condition in dtrie_delete is node==NULL. Suppose the case when there
is no SHM memory left when trying to dtrie_insert(). The memory gets freed
by shm_free() but the pointer still points to it. This leads to segfault when
dtrie_delete tries to access that memory zone, in the given case. GDB says:
"Cannot access memory at address 0x1130000001d"
Stefan Mititelu vor 10 Jahren
Ursprung
Commit
60ffee9cf5
1 geänderte Dateien mit 1 neuen und 0 gelöschten Zeilen
  1. 1 0
      lib/trie/dtrie.c

+ 1 - 0
lib/trie/dtrie.c

@@ -152,6 +152,7 @@ int dtrie_insert(struct dtrie_node_t *root, const char *number, const unsigned i
 			if(node->child[digit]->child == NULL){
 				SHM_MEM_ERROR;
 				shm_free(node->child[digit]);
+				node->child[digit] = NULL;
 				return -1;
 			}
 			LM_DBG("allocate %lu bytes for %d root children pointer at %p\n",