• Paul Eggert's avatar
    Fix temacs hybrid_malloc core dump · ac1ceadc
    Paul Eggert authored
    Without this patch, ./temacs would dump core sometimes on Fedora
    25 x86-64.  The problem was that the hybrid allocator assumed that
    all pointers into bss_sbrk_buffer are allocated via gmalloc.  This
    assumption is not true on Fedora, because the standard memory
    allocator calls gdefault_morecore, which means its blocks are
    interleaved with our blocks.  Usually the code happened to work,
    because our data structures agreed with the glibc data structures,
    but this was merely luck due to a shared pedigree, and as glibc
    mutates our luck has run out.
    * src/gmalloc.c (ALLOCATED_BEFORE_DUMPING) [HYBRID_MALLOC]:
    Remove; no longer needed.
    (BLOCK): Use unsigned division, as that does the right thing near zero.
    (register_heapinfo, __malloc_internal_nolock, __free_internal_nolock)
    (_realloc_internal_nolock):
    Big blocks now have type -1, not 0, as 0 now means the block is
    not ours.
    (morecore_nolock): Omit now-unnecessary casts to size_t.
    (allocated_via_gmalloc) [HYBRID_MALLOC]: New function.
    (hybrid_free, hybrid_realloc) [HYBRID_MALLOC]: Use it, to
    avoid calling the wrong free or realloc function in some cases.
    ac1ceadc
gmalloc.c 57.8 KB