Module: sip-router Branch: master Commit: f9477aa2bec8508197837875ebc199f1bf569fa4 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f9477aa2...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Wed Jun 24 16:08:09 2009 +0300
* modules/lcr: fixed crash when module initialization failed
* Added checks that shared memory has been really allocated before trying to free it. Fixes crash when during failed module initialization.
---
modules/lcr/lcr_mod.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c index 5a1619f..d3e9d17 100644 --- a/modules/lcr/lcr_mod.c +++ b/modules/lcr/lcr_mod.c @@ -221,9 +221,11 @@ static int_str defunct_gw_avp; static int lcr_id_avp_type; static int_str lcr_id_avp;
-struct gw_info **gwtp; /* Pointer to gw table pointer table */ +/* Pointer to gw table pointer table */ +struct gw_info **gwtp = (struct gw_info **)NULL;
-struct lcr_info ***lcrtp; /* Pointer to lcr hash table pointer table */ +/* Pointer to lcr hash table pointer table */ +struct lcr_info ***lcrtp = (struct lcr_info ***)NULL;
/* @@ -571,10 +573,6 @@ static int mod_init(void) } lcr_dbf.close(dbh);
- /* Reset all shm pointers */ - gwtp = (struct gw_info **)NULL; - lcrtp = (struct lcr_info ***)NULL; - /* Allocate gw related shared memory */ /* gw table pointer table, index 0 points to temp gw table */ gwtp = (struct gw_info **)shm_malloc(sizeof(struct gw_info *) * @@ -583,6 +581,7 @@ static int mod_init(void) LM_ERR("no memory for gw table pointer table\n"); goto err; } + memset(gwtp, 0, sizeof(struct gw_info *) * (lcr_count + 1)); /* gw tables */ for (i = 0; i <= lcr_count; i++) { gwtp[i] = (struct gw_info *)shm_malloc(sizeof(struct gw_info) * @@ -602,6 +601,7 @@ static int mod_init(void) LM_ERR("no memory for lcr hash table pointer table\n"); goto err; } + memset(lcrtp, 0, sizeof(struct lcr_info **) * (lcr_count + 1)); /* lcr hash tables */ /* Last entry in hash table contains list of different prefix lengths */ for (i = 0; i <= lcr_count; i++) { @@ -677,18 +677,18 @@ static void free_shared_memory(void) { int i; for (i = 0; i <= lcr_count; i++) { - if (gwtp[i]) { + if (gwtp && gwtp[i]) { shm_free(gwtp[i]); gwtp[i] = 0; } - if (lcrtp[i]) { + if (lcrtp && lcrtp[i]) { lcr_hash_table_contents_free(lcrtp[i]); shm_free(lcrtp[i]); lcrtp[i] = 0; } } - shm_free(gwtp); - shm_free(lcrtp); + if (gwtp) shm_free(gwtp); + if (lcrtp) shm_free(lcrtp); if (reload_lock) { lock_destroy(reload_lock); lock_dealloc(reload_lock);