[asterisk-commits] rmudgett: trunk r400271 - in /trunk: ./ apps/ main/ res/ res/stasis_recording/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 2 12:12:51 CDT 2013


Author: rmudgett
Date: Wed Oct  2 12:12:49 2013
New Revision: 400271

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=400271
Log:
MALLOC_DEBUG: Fix some misuses of free() when MALLOC_DEBUG is enabled.

* There were several places in ARI where an external library was mallocing
memory that must always be released with free().  When MALLOC_DEBUG is
enabled, free() is redirected to the MALLOC_DEBUG version.  Since the
external library call still uses the normal malloc(), MALLOC_DEBUG
complains that the freed memory block is not registered and will not free
it.  These cases must use ast_std_free().

* Changed calls to asprintf() and vasprintf() to the equivalent
ast_asprintf() and ast_vasprintf() versions respectively.
........

Merged revisions 400270 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/apps/app_stack.c
    trunk/main/json.c
    trunk/main/stasis_cache.c
    trunk/main/utils.c
    trunk/res/res_ari.c
    trunk/res/stasis_recording/stored.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Wed Oct  2 12:12:49 2013
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-399305,399307-400181,400194,400196,400205,400217,400227,400236,400245,400254,400256,400265,400268
+/branches/12:1-398558,398560-398577,398579-399305,399307-400181,400194,400196,400205,400217,400227,400236,400245,400254,400256,400265,400268,400270

Modified: trunk/apps/app_stack.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_stack.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/apps/app_stack.c (original)
+++ trunk/apps/app_stack.c Wed Oct  2 12:12:49 2013
@@ -1215,8 +1215,7 @@
 		ast_agi_send(agi->fd, chan, "200 result=%d Gosub failed\n", res);
 	}
 
-	/* Must use free because the memory was allocated by asprintf(). */
-	free(gosub_args);
+	ast_free(gosub_args);
 
 	ast_channel_lock(chan);
 	ast_debug(4, "%s Ending location: %s,%s,%d\n", ast_channel_name(chan),

Modified: trunk/main/json.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/json.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/main/json.c (original)
+++ trunk/main/json.c Wed Oct  2 12:12:49 2013
@@ -340,10 +340,10 @@
 	json_t *ret = NULL;
 
 	if (format) {
-		int err = vasprintf(&str, format, args);
+		int err = ast_vasprintf(&str, format, args);
 		if (err > 0) {
 			ret = json_string(str);
-			free(str);
+			ast_free(str);
 		}
 	}
 	return (struct ast_json *)ret;

Modified: trunk/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_cache.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/main/stasis_cache.c (original)
+++ trunk/main/stasis_cache.c Wed Oct  2 12:12:49 2013
@@ -448,10 +448,10 @@
 {
 	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
 	struct stasis_subscription *sub;
-	RAII_VAR(char *, new_name, NULL, free);
+	RAII_VAR(char *, new_name, NULL, ast_free);
 	int ret;
 
-	ret = asprintf(&new_name, "%s-cached", stasis_topic_name(original_topic));
+	ret = ast_asprintf(&new_name, "%s-cached", stasis_topic_name(original_topic));
 	if (ret < 0) {
 		return NULL;
 	}

Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Wed Oct  2 12:12:49 2013
@@ -656,9 +656,10 @@
 	}
 
 	pthread_mutex_destroy(&lock_info->lock);
-	if (lock_info->thread_name)
-		free((void *) lock_info->thread_name);
-	free(lock_info);
+	if (lock_info->thread_name) {
+		ast_free((void *) lock_info->thread_name);
+	}
+	ast_free(lock_info);
 }
 
 /*!
@@ -2184,7 +2185,7 @@
 
 static int safe_mkdir(const char *base_path, char *path, int mode)
 {
-	RAII_VAR(char *, absolute_path, NULL, free);
+	RAII_VAR(char *, absolute_path, NULL, ast_std_free);
 
 	absolute_path = realpath(path, NULL);
 
@@ -2206,7 +2207,7 @@
 		int res;
 
 		while (path_term) {
-			RAII_VAR(char *, absolute_subpath, NULL, free);
+			RAII_VAR(char *, absolute_subpath, NULL, ast_std_free);
 
 			/* Truncate the path one past the slash */
 			char c = *(path_term + 1);
@@ -2254,7 +2255,7 @@
 
 int ast_safe_mkdir(const char *base_path, const char *path, int mode)
 {
-	RAII_VAR(char *, absolute_base_path, NULL, free);
+	RAII_VAR(char *, absolute_base_path, NULL, ast_std_free);
 	RAII_VAR(char *, p, NULL, ast_free);
 
 	if (base_path == NULL || path == NULL) {

Modified: trunk/res/res_ari.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_ari.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/res/res_ari.c (original)
+++ trunk/res/res_ari.c Wed Oct  2 12:12:49 2013
@@ -554,8 +554,8 @@
 			  struct ast_ari_response *response)
 {
 	RAII_VAR(struct ast_str *, absolute_path_builder, NULL, ast_free);
-	RAII_VAR(char *, absolute_api_dirname, NULL, free);
-	RAII_VAR(char *, absolute_filename, NULL, free);
+	RAII_VAR(char *, absolute_api_dirname, NULL, ast_std_free);
+	RAII_VAR(char *, absolute_filename, NULL, ast_std_free);
 	struct ast_json *obj = NULL;
 	struct ast_variable *host = NULL;
 	struct ast_json_error error = {};

Modified: trunk/res/stasis_recording/stored.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis_recording/stored.c?view=diff&rev=400271&r1=400270&r2=400271
==============================================================================
--- trunk/res/stasis_recording/stored.c (original)
+++ trunk/res/stasis_recording/stored.c Wed Oct  2 12:12:49 2013
@@ -78,7 +78,7 @@
 {
 	RAII_VAR(char *, relative_dir, NULL, ast_free);
 	RAII_VAR(char *, absolute_dir, NULL, ast_free);
-	RAII_VAR(char *, real_dir, NULL, free);
+	RAII_VAR(char *, real_dir, NULL, ast_std_free);
 	char *last_slash;
 	const char *file_portion;
 
@@ -108,7 +108,16 @@
 		return -1;
 	}
 
+#if defined(__AST_DEBUG_MALLOC)
 	*dir = ast_strdup(real_dir); /* Dupe so we can ast_free() */
+#else
+	/*
+	 * ast_std_free() and ast_free() are the same thing at this time
+	 * so we don't need to dupe.
+	 */
+	*dir = real_dir;
+	real_dir = NULL;
+#endif	/* defined(__AST_DEBUG_MALLOC) */
 	*file = ast_strdup(file_portion);
 	return 0;
 }




More information about the asterisk-commits mailing list