[sr-dev] git:master:33e082dd: debugger: destroy debugger shm hashtable

Stefan Mititelu stefan.mititelu at 1and1.ro
Wed Jan 6 15:13:45 CET 2016


Module: kamailio
Branch: master
Commit: 33e082dd314a333c62bfbc176a392702cfd9f4cd
URL: https://github.com/kamailio/kamailio/commit/33e082dd314a333c62bfbc176a392702cfd9f4cd

Author: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Committer: Stefan Mititelu <stefan.mititelu at 1and1.ro>
Date: 2016-01-05T13:26:32+02:00

debugger: destroy debugger shm hashtable

Add a dbg_destroy_mod_levels() functions to be called on mod_destroy(),
thus avoiding shm leaks.

---

Modified: modules/debugger/debugger_api.c
Modified: modules/debugger/debugger_api.h
Modified: modules/debugger/debugger_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/33e082dd314a333c62bfbc176a392702cfd9f4cd.diff
Patch: https://github.com/kamailio/kamailio/commit/33e082dd314a333c62bfbc176a392702cfd9f4cd.patch

---

diff --git a/modules/debugger/debugger_api.c b/modules/debugger/debugger_api.c
index 014d5be..f060b36 100644
--- a/modules/debugger/debugger_api.c
+++ b/modules/debugger/debugger_api.c
@@ -1161,6 +1161,63 @@ int dbg_init_mod_levels(int dbg_mod_hash_size)
 	return 0;
 }
 
+/**
+ *
+ */
+int dbg_destroy_mod_levels()
+{
+	int i;
+	dbg_mod_level_t *itl = NULL;
+	dbg_mod_level_t *itlp = NULL;
+
+	dbg_mod_facility_t *itf = NULL;
+	dbg_mod_facility_t *itfp = NULL;
+
+	if (_dbg_mod_table_size <= 0)
+		return 0;
+
+	if (_dbg_mod_table == NULL)
+		return 0;
+
+	for (i = 0; i < _dbg_mod_table_size; i++) {
+		// destroy level list
+		lock_get(&_dbg_mod_table[i].lock);
+		itl = _dbg_mod_table[i].first;
+		while (itl) {
+			itlp = itl;
+			itl = itl->next;
+			shm_free(itlp);
+		}
+		lock_release(&_dbg_mod_table[i].lock);
+
+		// destroy facility list
+		lock_get(&_dbg_mod_table[i].lock_ft);
+		itf = _dbg_mod_table[i].first_ft;
+		while (itf) {
+			itfp = itf;
+			itf = itf->next;
+			shm_free(itfp);
+		}
+		lock_release(&_dbg_mod_table[i].lock_ft);
+
+		// destroy locks
+		lock_destroy(&_dbg_mod_table[i].lock);
+		lock_destroy(&_dbg_mod_table[i].lock_ft);
+
+		// reset all
+		_dbg_mod_table[i].first = NULL;
+		_dbg_mod_table[i].first_ft = NULL;
+	}
+
+	// free table
+	shm_free(_dbg_mod_table);
+	_dbg_mod_table = NULL;
+
+	LM_DBG("Destroyed _dbg_mod_table, size %d\n", _dbg_mod_table_size);
+
+	return 0;
+}
+
 /*
  * case insensitive hashing - clone here to avoid usage of LOG*()
  * - s1 - str to hash
diff --git a/modules/debugger/debugger_api.h b/modules/debugger/debugger_api.h
index e41b15a..7d034c2 100644
--- a/modules/debugger/debugger_api.h
+++ b/modules/debugger/debugger_api.h
@@ -34,6 +34,7 @@ int dbg_init_mypid(void);
 int dbg_init_rpc(void);
 
 int dbg_init_mod_levels(int _dbg_mod_hash_size);
+int dbg_destroy_mod_levels();
 int dbg_set_mod_debug_level(char *mname, int mnlen, int *mlevel);
 int dbg_set_mod_debug_facility(char *mname, int mnlen, int *mfacility);
 void dbg_enable_mod_levels(void);
diff --git a/modules/debugger/debugger_mod.c b/modules/debugger/debugger_mod.c
index e779825..e37ab83 100644
--- a/modules/debugger/debugger_mod.c
+++ b/modules/debugger/debugger_mod.c
@@ -507,6 +507,7 @@ static int child_init(int rank)
 static void mod_destroy(void)
 {
 	dbg_cfg = NULL;
+	dbg_destroy_mod_levels();
 }
 
 /**




More information about the sr-dev mailing list