[sr-dev] git:master: htable: check if hash table entries are initialized in detroy function

Daniel-Constantin Mierla miconda at gmail.com
Sun May 22 17:25:31 CEST 2011


Module: sip-router
Branch: master
Commit: 72938bf706a75ecd4edf63dcfa2551b9ce40976b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=72938bf706a75ecd4edf63dcfa2551b9ce40976b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun May 22 17:21:54 2011 +0200

htable: check if hash table entries are initialized in detroy function

- one of last updates to htable changed initialization to be directly in
  shared memory, while hash table slots are initialied in mod init
  funtion, causing crash of the module if config file has errors and
  proper starting does not happen
- reported by Juha Heinanen

---

 modules_k/htable/ht_api.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/modules_k/htable/ht_api.c b/modules_k/htable/ht_api.c
index da473e6..5c5298b 100644
--- a/modules_k/htable/ht_api.c
+++ b/modules_k/htable/ht_api.c
@@ -320,20 +320,23 @@ int ht_destroy(void)
 	while(ht)
 	{
 		ht0 = ht->next;
-		for(i=0; i<ht->htsize; i++)
+		if(ht->entries!=NULL)
 		{
-			/* free entries */
-			it = ht->entries[i].first;
-			while(it)
+			for(i=0; i<ht->htsize; i++)
 			{
-				it0 = it;
-				it = it->next;
-				ht_cell_free(it0);
+				/* free entries */
+				it = ht->entries[i].first;
+				while(it)
+				{
+					it0 = it;
+					it = it->next;
+					ht_cell_free(it0);
+				}
+				/* free locks */
+				lock_destroy(&ht->entries[i].lock);
 			}
-			/* free locks */
-			lock_destroy(&ht->entries[i].lock);
+			shm_free(ht->entries);
 		}
-		shm_free(ht->entries);
 		shm_free(ht);
 		ht = ht0;
 	}




More information about the sr-dev mailing list