OSDN Git Service

Fix race in malloc debug option free_track.
authorChristopher Ferris <cferris@google.com>
Wed, 16 Mar 2016 05:39:39 +0000 (22:39 -0700)
committerChristopher Ferris <cferris@google.com>
Thu, 17 Mar 2016 19:29:31 +0000 (12:29 -0700)
commit97fce67302a80bf282bff118cfa96936c5ad9e81
treedde94519ee9420eee677ffbd6c423d9a61bd156d
parent4451b53c3761b46fa33a3e47bfb0c62ca47e5fbb
Fix race in malloc debug option free_track.

The free track mechanism could fail if, at the same time a free occurs,
another thread is trying to free and verify the same allocation. This
doesn't work if the freed allocation is added to the list and we still
do work on it. The fix is to only add to the free list when we are done
with the allocation.

Also fix a problem where the usable size is computed incorrectly because
two of the arguments where reversed.

In addition, add a check that the allocation being verified has the correct
tag before trying to check the body of the allocation.

Add a test to catch the original failure.

Add a test for the tag being different.

Bug: 27601650

(cherry picked from commit d0919623a2ef56107590eca9a9522a250fb8bd4a)

Change-Id: Ie1aa4d9a829da9a96de9b8bd1cc8fc681e9cab15
libc/malloc_debug/FreeTrackData.cpp
libc/malloc_debug/malloc_debug.cpp
libc/malloc_debug/tests/malloc_debug_unit_tests.cpp