[sr-dev] git:master: modules/debugger: fixed last commit.

Victor Seva linuxmaniac at torreviejawireless.org
Mon Jun 3 18:44:51 CEST 2013


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

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date:   Mon Jun  3 18:43:51 2013 +0200

modules/debugger: fixed last commit.

- checked malloc result on dbg_init_pvcache.
- checked result of dbg_init_pvcache on mod_init.
- removed commented code.

---

 modules/debugger/debugger_api.c |   18 ++++++++----------
 modules/debugger/debugger_api.h |    2 +-
 modules/debugger/debugger_mod.c |    6 +++++-
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/modules/debugger/debugger_api.c b/modules/debugger/debugger_api.c
index 1f42d74..f0dbdce 100644
--- a/modules/debugger/debugger_api.c
+++ b/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);
diff --git a/modules/debugger/debugger_api.h b/modules/debugger/debugger_api.h
index 6a45678..54d5c59 100644
--- a/modules/debugger/debugger_api.h
+++ b/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
 
diff --git a/modules/debugger/debugger_mod.c b/modules/debugger/debugger_mod.c
index 18b50e6..f048b0d 100644
--- a/modules/debugger/debugger_mod.c
+++ b/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();
 }




More information about the sr-dev mailing list