[asterisk-commits] rmudgett: branch 1.8 r321926 - in /branches/1.8: cdr/ cel/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 3 17:09:40 CDT 2011


Author: rmudgett
Date: Fri Jun  3 17:09:36 2011
New Revision: 321926

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=321926
Log:
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

Modified:
    branches/1.8/cdr/cdr_radius.c
    branches/1.8/cel/cel_radius.c

Modified: branches/1.8/cdr/cdr_radius.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cdr/cdr_radius.c?view=diff&rev=321926&r1=321925&r2=321926
==============================================================================
--- branches/1.8/cdr/cdr_radius.c (original)
+++ branches/1.8/cdr/cdr_radius.c Fri Jun  3 17:09:36 2011
@@ -224,6 +224,10 @@
 static int unload_module(void)
 {
 	ast_cdr_unregister(name);
+	if (rh) {
+		rc_destroy(rh);
+		rh = NULL;
+	}
 	return 0;
 }
 
@@ -243,8 +247,17 @@
 	} 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 @@
 	/* 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");
-		return AST_MODULE_LOAD_DECLINE;
-	}
-
-	ast_cdr_register(name, desc, radius_log);
-	return AST_MODULE_LOAD_SUCCESS;
+		rc_destroy(rh);
+		rh = NULL;
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	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",

Modified: branches/1.8/cel/cel_radius.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/cel/cel_radius.c?view=diff&rev=321926&r1=321925&r2=321926
==============================================================================
--- branches/1.8/cel/cel_radius.c (original)
+++ branches/1.8/cel/cel_radius.c Fri Jun  3 17:09:36 2011
@@ -208,6 +208,10 @@
 	if (event_sub) {
 		event_sub = ast_event_unsubscribe(event_sub);
 	}
+	if (rh) {
+		rc_destroy(rh);
+		rh = NULL;
+	}
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -227,8 +231,17 @@
 		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))) {
@@ -239,12 +252,15 @@
 	/* 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;




More information about the asterisk-commits mailing list