瀏覽代碼

debugger: destroy debugger shm hashtable

Add a dbg_destroy_mod_levels() functions to be called on mod_destroy(),
thus avoiding shm leaks.
Stefan Mititelu 9 年之前
父節點
當前提交
33e082dd31
共有 3 個文件被更改,包括 59 次插入0 次删除
  1. 57 0
      modules/debugger/debugger_api.c
  2. 1 0
      modules/debugger/debugger_api.h
  3. 1 0
      modules/debugger/debugger_mod.c

+ 57 - 0
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

+ 1 - 0
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);

+ 1 - 0
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();
 }
 
 /**