Merged revisions 321926 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r321926 | rmudgett | 2011-06-03 17:09:36 -0500 (Fri, 03 Jun 2011) | 18 lines
  
  Asterisk crash when unloading cdr_radius/cel_radius.
  
  The rc_openlog() API call is passed a string that is used by openlog() to
  format log messages.  The openlog() does not copy the string it just keeps
  a pointer to it.  When the module is unloaded, the string is gone from
  memory.  Depending upon module load order and if the other module then has
  an error, a crash happens.
  
  * Pass rc_openlog() a strdup'd string with the understanding that there
  will be a small memory leak if the cdr_radius/cel_radius modules are
  unloaded.
  
  * Call rc_destroy() to free the rc handle memory when the module is
  unloaded.
  
  JIRA AST-483
  JIRA SWP-3062
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@321927 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett 2011-06-03 22:15:56 +00:00
parent 31bcafab5b
commit c8548bad22
2 changed files with 43 additions and 7 deletions

View File

@ -224,6 +224,10 @@ return_cleanup:
static int unload_module(void)
{
ast_cdr_unregister(name);
if (rh) {
rc_destroy(rh);
rh = NULL;
}
return 0;
}
@ -243,8 +247,17 @@ static int load_module(void)
} else
return AST_MODULE_LOAD_DECLINE;
/* start logging */
rc_openlog("asterisk");
/*
* start logging
*
* NOTE: Yes this causes a slight memory leak if the module is
* unloaded. However, it is better than a crash if cdr_radius
* and cel_radius are both loaded.
*/
tmp = ast_strdup("asterisk");
if (tmp) {
rc_openlog((char *) tmp);
}
/* read radiusclient-ng config file */
if (!(rh = rc_read_config(radiuscfg))) {
@ -255,11 +268,18 @@ static int load_module(void)
/* read radiusclient-ng dictionaries */
if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
rc_destroy(rh);
rh = NULL;
return AST_MODULE_LOAD_DECLINE;
}
ast_cdr_register(name, desc, radius_log);
return AST_MODULE_LOAD_SUCCESS;
if (ast_cdr_register(name, desc, radius_log)) {
rc_destroy(rh);
rh = NULL;
return AST_MODULE_LOAD_DECLINE;
} else {
return AST_MODULE_LOAD_SUCCESS;
}
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "RADIUS CDR Backend",

View File

@ -206,6 +206,10 @@ static int unload_module(void)
if (event_sub) {
event_sub = ast_event_unsubscribe(event_sub);
}
if (rh) {
rc_destroy(rh);
rh = NULL;
}
return AST_MODULE_LOAD_SUCCESS;
}
@ -225,8 +229,17 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
/* start logging */
rc_openlog("asterisk");
/*
* start logging
*
* NOTE: Yes this causes a slight memory leak if the module is
* unloaded. However, it is better than a crash if cdr_radius
* and cel_radius are both loaded.
*/
tmp = ast_strdup("asterisk");
if (tmp) {
rc_openlog((char *) tmp);
}
/* read radiusclient-ng config file */
if (!(rh = rc_read_config(radiuscfg))) {
@ -237,12 +250,15 @@ static int load_module(void)
/* read radiusclient-ng dictionaries */
if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
rc_destroy(rh);
rh = NULL;
return AST_MODULE_LOAD_DECLINE;
}
event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END);
if (!event_sub) {
rc_destroy(rh);
rh = NULL;
return AST_MODULE_LOAD_DECLINE;
} else {
return AST_MODULE_LOAD_SUCCESS;