• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂3538ba34e0e415105d3fe235605e6dba1597ad98 (tree)
時間2019-10-01 02:29:07
作者Kjetil Oftedal <oftedal@gmai...>
CommiterWaldemar Brodkorb

Log Message

malloc: Add missing locks for some paths (valloc/memalign/posix_memalign)

The internal heap structures were not protected properly in
memalign(). If multiple threads were concurrently allocating memory and
one of them were requesting aligned memory via valloc,memalign or
posix_memalign the internal heap data structures could be corrupted.

Signed-off-by: Kjetil Oftedal <oftedal@gmail.com>

Change Summary

差異

--- a/libc/stdlib/malloc/memalign.c
+++ b/libc/stdlib/malloc/memalign.c
@@ -77,7 +77,9 @@ memalign (size_t alignment, size_t size)
7777 init_size = addr - tot_addr;
7878 }
7979
80+ __heap_lock (&__malloc_heap_lock);
8081 __heap_free (heap, base, init_size);
82+ __heap_unlock (&__malloc_heap_lock);
8183
8284 /* Remember that we've freed the initial part of MEM. */
8385 base += init_size;
@@ -85,9 +87,11 @@ memalign (size_t alignment, size_t size)
8587
8688 /* Return the end part of MEM to the heap, unless it's too small. */
8789 end_addr = addr + size;
88- if (end_addr + MALLOC_REALLOC_MIN_FREE_SIZE < tot_end_addr)
90+ if (end_addr + MALLOC_REALLOC_MIN_FREE_SIZE < tot_end_addr) {
91+ __heap_lock (&__malloc_heap_lock);
8992 __heap_free (heap, (void *)end_addr, tot_end_addr - end_addr);
90- else
93+ __heap_unlock (&__malloc_heap_lock);
94+ } else
9195 /* We didn't free the end, so include it in the size. */
9296 end_addr = tot_end_addr;
9397