[asterisk-commits] mjordan: trunk r432455 - in /trunk: ./ main/translate.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 4 12:55:10 CST 2015


Author: mjordan
Date: Wed Mar  4 12:55:08 2015
New Revision: 432455

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432455
Log:
translate: Prevent invalid memory accesses on fast shutdown

When a 'core restart now' or 'core stop now' is executed and a channel is
currently in a media operation, the translator matrix can be destroyed while a
channel is currently blocked on getting the best translation choice
(see ast_translator_best_choice). When the channel gets the mutex, the
translation matrix now has invalid memory, and Asterisk crashes.

This patch does two things:
(1) We now only clean up the translation matrix on a graceful shutdown. In that
    case, there are no channels, and so there is no risk of this occurring.
(2) We also now set the __matrix and __indextable to NULL. In some initial
    backtraces when this occurred, it looked as if there was a memory corruption
    occurring, and it wasn't until we determined that something had restarted
    Asterisk that the issue became clear. By setting these to NULL on shutdown,
    it becomes a bit easier to determine why a crash is occurring.

Note that we could litter the code with NULL checks on the __matrix, but the
act of making the translation matrix cleaned up on shutdown should preclude
this issue from occurring in the first place, and this part of the code needs
to be as fast as possible.

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

Merged revisions 432453 from http://svn.asterisk.org/svn/asterisk/branches/13

Modified:
    trunk/   (props changed)
    trunk/main/translate.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/translate.c?view=diff&rev=432455&r1=432454&r2=432455
==============================================================================
--- trunk/main/translate.c (original)
+++ trunk/main/translate.c Wed Mar  4 12:55:08 2015
@@ -1484,7 +1484,9 @@
 		ast_free(__matrix[x]);
 	}
 	ast_free(__matrix);
+	__matrix = NULL;
 	ast_free(__indextable);
+	__indextable = NULL;
 	ast_rwlock_unlock(&tablelock);
 	ast_rwlock_destroy(&tablelock);
 }
@@ -1495,6 +1497,6 @@
 	ast_rwlock_init(&tablelock);
 	res = matrix_resize(1);
 	res |= ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
-	ast_register_atexit(translate_shutdown);
+	ast_register_cleanup(translate_shutdown);
 	return res;
 }




More information about the asterisk-commits mailing list