[asterisk-commits] wdoekes: branch 1.8 r396427 - in /branches/1.8: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 8 15:14:32 CDT 2013


Author: wdoekes
Date: Thu Aug  8 15:14:27 2013
New Revision: 396427

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396427
Log:
Consistent memory allocation by ast_bt_get_symbols.

Always use ast_alloc/ast_free. This is handled differently in trunk (r391012).

Review: https://reviewboard.asterisk.org/r/2580/

Modified:
    branches/1.8/include/asterisk/logger.h
    branches/1.8/main/astobj2.c
    branches/1.8/main/logger.c
    branches/1.8/main/utils.c

Modified: branches/1.8/include/asterisk/logger.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/logger.h?view=diff&rev=396427&r1=396426&r2=396427
==============================================================================
--- branches/1.8/include/asterisk/logger.h (original)
+++ branches/1.8/include/asterisk/logger.h Thu Aug  8 15:14:27 2013
@@ -304,7 +304,7 @@
  * \param addresses A list of addresses, such as the ->addresses structure element of struct ast_bt.
  * \param num_frames Number of addresses in the addresses list
  * \retval NULL Unable to allocate memory
- * \return List of strings
+ * \return List of strings. Free the entire list with a single ast_free call.
  * \since 1.6.2.16
  */
 char **ast_bt_get_symbols(void **addresses, size_t num_frames);

Modified: branches/1.8/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/astobj2.c?view=diff&rev=396427&r1=396426&r2=396427
==============================================================================
--- branches/1.8/main/astobj2.c (original)
+++ branches/1.8/main/astobj2.c Thu Aug  8 15:14:27 2013
@@ -98,7 +98,7 @@
 	for(i = 0; i < c; i++) {
 		ast_verbose("%d: %p %s\n", i, addresses[i], strings[i]);
 	}
-	free(strings);
+	ast_free(strings);
 }
 #endif
 

Modified: branches/1.8/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/logger.c?view=diff&rev=396427&r1=396426&r2=396427
==============================================================================
--- branches/1.8/main/logger.c (original)
+++ branches/1.8/main/logger.c Thu Aug  8 15:14:27 2013
@@ -1474,7 +1474,31 @@
 		}
 	}
 #else /* !defined(BETTER_BACKTRACES) */
-	strings = backtrace_symbols(addresses, num_frames);
+	if ((strings = backtrace_symbols(addresses, num_frames))) {
+		/* Re-do value into ast_alloc'ed memory */
+		char **ast_strings;
+		char *p;
+		unsigned size = num_frames + sizeof(*strings);
+		int i;
+		for (i = 0; i < num_frames; ++i) {
+			size += strlen(strings[i]) + 1;
+		}
+#undef free
+		if (!(ast_strings = ast_malloc(size))) {
+			free(strings);
+			ast_log(LOG_WARNING, "Unable to re-allocate space for backtrace structure\n");
+			return NULL;
+		}
+		p = (char *) (ast_strings + num_frames);
+		for (i = 0; i < num_frames; ++i) {
+			unsigned len = strlen(strings[i]) + 1;
+			ast_strings[i] = p;
+			memcpy(p, strings[i], len);
+			p += len;
+		}
+		free(strings);
+		strings = ast_strings;
+	}
 #endif /* defined(BETTER_BACKTRACES) */
 	return strings;
 }
@@ -1499,9 +1523,7 @@
 			ast_log(LOG_DEBUG, "#%d: [%p] %s\n", i - 3, bt->addresses[i], strings[i]);
 		}
 
-		/* MALLOC_DEBUG will erroneously report an error here, unless we undef the macro. */
-#undef free
-		free(strings);
+		ast_free(strings);
 	} else {
 		ast_debug(1, "Could not allocate memory for backtrace\n");
 	}

Modified: branches/1.8/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/utils.c?view=diff&rev=396427&r1=396426&r2=396427
==============================================================================
--- branches/1.8/main/utils.c (original)
+++ branches/1.8/main/utils.c Thu Aug  8 15:14:27 2013
@@ -851,7 +851,7 @@
 			ast_str_append(str, 0, "\t%s\n", symbols[frame_iterator]);
 		}
 
-		free(symbols);
+		ast_free(symbols);
 	} else {
 		ast_str_append(str, 0, "\tCouldn't retrieve backtrace symbols\n");
 	}




More information about the asterisk-commits mailing list