From 7a9368a1174cb15b9f1d6342e0e10dd90dae238d Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 15 Nov 2017 11:39:01 +0100 Subject: malloc: Add missing arena lock in malloc_info [BZ #22408] Obtain the size information while the arena lock is acquired, and only print it later. --- malloc/malloc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'malloc/malloc.c') diff --git a/malloc/malloc.c b/malloc/malloc.c index f94d51cca1..0494e8c39f 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5455,6 +5455,15 @@ __malloc_info (int options, FILE *fp) avail += sizes[NFASTBINS - 1 + i].total; } + size_t heap_size = 0; + size_t heap_mprotect_size = 0; + if (ar_ptr != &main_arena) + { + heap_info *heap = heap_for_ptr (top (ar_ptr)); + heap_size = heap->size; + heap_mprotect_size = heap->mprotect_size; + } + __libc_lock_unlock (ar_ptr->mutex); total_nfastblocks += nfastblocks; @@ -5488,13 +5497,12 @@ __malloc_info (int options, FILE *fp) if (ar_ptr != &main_arena) { - heap_info *heap = heap_for_ptr (top (ar_ptr)); fprintf (fp, "\n" "\n", - heap->size, heap->mprotect_size); - total_aspace += heap->size; - total_aspace_mprotect += heap->mprotect_size; + heap_size, heap_mprotect_size); + total_aspace += heap_size; + total_aspace_mprotect += heap_mprotect_size; } else { -- cgit v1.2.3