]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix invalid access to disposed memory in main/data unit test
authorMatthew Jordan <mjordan@digium.com>
Tue, 20 Aug 2013 01:25:46 +0000 (01:25 +0000)
committerMatthew Jordan <mjordan@digium.com>
Tue, 20 Aug 2013 01:25:46 +0000 (01:25 +0000)
It is not safe to iterate over a macro'd list of ao2 objects, deref them such
that the item's destructor is called, and leave them in the list. The list
macro to iterate over items requires the item to be a valid allocated object
in order to proceed to the next item; with MALLOC_DEBUG on the corruption of
the linked list is caught in the crash.

This patch fixes the invalid access to free'd memory by removing the ao2 item
from the list before de-refing it.

Note that this is a backport of r396915 from Asterisk trunk.
........

Merged revisions 396958 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 396961 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/11.2@396982 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/data.c

index 7a19b1f8f74d730f6599b9ecaf2791c87423e4c4..208205839b6b5f112edb7ccfa38286379b736091 100644 (file)
@@ -1631,7 +1631,7 @@ static void data_filter_destructor(void *obj)
 {
        struct data_filter *filter = obj, *globres;
 
-       AST_LIST_TRAVERSE(&(filter->glob_list), globres, list) {
+       while ((globres = AST_LIST_REMOVE_HEAD(&(filter->glob_list), list))) {
                ao2_ref(globres, -1);
        }