Browse Source

modules/debugger: fixed last commit.

- checked malloc result on dbg_init_pvcache.
- checked result of dbg_init_pvcache on mod_init.
- removed commented code.
Victor Seva 12 years ago
parent
commit
26b15ad000
3 changed files with 14 additions and 12 deletions
  1. 8 10
      modules/debugger/debugger_api.c
  2. 1 1
      modules/debugger/debugger_api.h
  3. 5 1
      modules/debugger/debugger_mod.c

+ 8 - 10
modules/debugger/debugger_api.c

@@ -1120,17 +1120,22 @@ typedef struct _dbg_pvcache {
 
 static dbg_pvcache_t **_dbg_pvcache = NULL;
 
-void dbg_init_pvcache()
+int dbg_init_pvcache()
 {
 	_dbg_pvcache = (dbg_pvcache_t**)pkg_malloc(sizeof(dbg_pvcache_t*)*DBG_PVCACHE_SIZE);
+	if(_dbg_pvcache==NULL)
+	{
+		LM_ERR("no more memory.\n");
+		return -1;
+	}
 	memset(_dbg_pvcache, 0, sizeof(dbg_pvcache_t*)*DBG_PVCACHE_SIZE);
+	return 0;
 }
 
 int dbg_assign_add(str *name, pv_spec_t *spec)
 {
 	dbg_pvcache_t *pvn, *last, *next;
 	unsigned int pvid;
-	//unsigned i = 0;
 
 	if(name==NULL||spec==NULL)
 		return -1;
@@ -1140,7 +1145,7 @@ int dbg_assign_add(str *name, pv_spec_t *spec)
 
 	pvid = get_hash1_raw((char *)&spec, sizeof(pv_spec_t*));
 	pvn = (dbg_pvcache_t*)pkg_malloc(sizeof(dbg_pvcache_t));
-	if(pvn==0)
+	if(pvn==NULL)
 	{
 		LM_ERR("no more memory\n");
 		return -1;
@@ -1157,14 +1162,11 @@ int dbg_assign_add(str *name, pv_spec_t *spec)
 	{
 		while(next)
 		{
-			//i++;
 			last = next;
 			next = next->next;
 		}
 		last->next = pvn;
 	}
-	/*LM_DBG("spec[%p] pvar[%.*s] added in cache[%d][%d]\n", spec,
-		name->len, name->s, pvid%DBG_PVCACHE_SIZE, i);*/
 	return 0;
 }
 
@@ -1173,7 +1175,6 @@ str *_dbg_pvcache_lookup(pv_spec_t *spec)
 	dbg_pvcache_t *pvi;
 	unsigned int pvid;
 	str *name = NULL;
-	//unsigned int i = 0;
 
 	if(spec==NULL)
 		return NULL;
@@ -1186,11 +1187,8 @@ str *_dbg_pvcache_lookup(pv_spec_t *spec)
 	while(pvi)
 	{
 		if(pvi->spec==spec) {
-			/*LM_DBG("spec[%p] pvar[%.*s] found in cache[%d][%d]\n", spec,
-				pvi->pvname->len, pvi->pvname->s, pvid%DBG_PVCACHE_SIZE, i);*/
 			return pvi->pvname;
 		}
-		//i++;
 		pvi = pvi->next;
 	}
 	name = pv_cache_get_name(spec);

+ 1 - 1
modules/debugger/debugger_api.h

@@ -37,7 +37,7 @@ int dbg_init_mod_levels(int _dbg_mod_hash_size);
 int dbg_set_mod_debug_level(char *mname, int mnlen, int *mlevel);
 void dbg_enable_mod_levels(void);
 
-void dbg_init_pvcache(void);
+int dbg_init_pvcache(void);
 void dbg_enable_log_assign(void);
 #endif
 

+ 5 - 1
modules/debugger/debugger_mod.c

@@ -137,7 +137,11 @@ static int mod_init(void)
 
 	if(_dbg_log_assign>0)
 	{
-		dbg_init_pvcache();
+		if(dbg_init_pvcache()!=0)
+		{
+			LM_ERR("failed to create pvcache\n");
+			return -1;
+		}
 	}
 	return dbg_init_bp_list();
 }