c - Bug in OS X 10.5 malloc? -


i'm writing program in c. have 2 main development machines, both macs. 1 running os x 10.5 , 32bit machine, other running os x 10.6 , 64 bits. program works fine when compiled , run on 64bit machine. however, when compile exact same program on 32bit machine runs while , crashes somewhere inside malloc. here's backtrace:

program received signal exc_bad_access, not access memory. reason: kern_invalid_address @ address: 0xeeb40fe0 0x9036d598 in small_malloc_from_free_list () (gdb) bt #0  0x9036d598 in small_malloc_from_free_list () #1  0x90365286 in szone_malloc () #2  0x903650b8 in malloc_zone_malloc () #3  0x9036504c in malloc () #4  0x0000b14c in xmalloc (s=2048) @ common.h:185 ... 

xmalloc custom wrapper calls exit if malloc returns null, it's not running out of memory.

if link same code -ltcmalloc works fine, suspect it's bug somewhere inside os x 10.5's default allocator. may program causing memory corruption somewhere , tcmalloc somehow doesn't tripped it. tried reproduce failure doing same sequence of mallocs , frees in different program worked fine.

so questions are:

  • has seen bug before? or, alternatively

  • how can debug this? e.g., there debug version of os x's malloc?

btw, these linked libraries:

$ otool -l ./interp  ./interp:     /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)     /usr/lib/libsystem.b.dylib (compatibility version 1.0.0, current version 111.1.5) 

update: yeah, it's heap corruption due writing past end off array, it's working now. should have run valgrind before posting question. nevertheless interested in techniques (other valgrind) how protect such kind of corruption, that.

have read manual page malloc() on macos x? in part, says:

debugging allocation errors

a number of facilities provided aid in debugging allocation errors in applications. these facilities controlled via environment variables. recognized environment variables , meanings documented below.

environment

the following environment variables change behavior of allocation-related functions.

  • malloclogfile <f>

    create/append messages given file path instead of writing standard error.

  • mallocguardedges

    if set, add guard page before , after each large block.

  • mallocdonotprotectprelude

    if set, not add guard page before large blocks, if mallocguardedges environment variable set.

  • mallocdonotprotectpostlude

    if set, not add guard page after large blocks, if mallocguardedges environment variable set.

  • mallocstacklogging

    if set, record stacks, tools leaks can used.

  • mallocstackloggingnocompact

    if set, record stacks in manner compatible malloc_history program.

  • mallocstackloggingdirectory

    if set, records stack logs directory specified instead of saving them default location (/tmp).

  • mallocscribble

    if set, fill memory has been allocated 0xaa bytes. increases likelihood program making assumptions contents of freshly allocated memory fail. if set, fill memory has been deallocated 0x55 bytes. increases likelihood program fail due accessing memory no longer allocated.

  • malloccheckheapstart <s>

    if set, specifies number of allocations <s> wait before begining periodic heap checks every <n> specified malloccheckheapeach. if malloccheckheapstart set malloccheckheapeach not specified, default check repetition 1000.

  • malloccheckheapeach <n>

    if set, run consistency check on heap every <n> operations. malloccheckheapeach meaningful if malloccheckheapstart set.

  • malloccheckheapsleep <t>

    sets number of seconds sleep (waiting debugger attach) when malloccheckheapstart set , heap corruption detected. default 100 seconds. setting 0 means not sleep @ all. setting negative number means sleep (for positive number of seconds) first time heap corruption detected.

  • malloccheckheapabort <b>

    when malloccheckheapstart set , set non-zero value, causes abort(3) called if heap corruption detected, instead of sleeping.

  • mallocerrorabort

    if set, causes abort(3) called if error encountered in malloc(3) or free(3) , such calling free(3) on pointer freed.

  • malloccorruptionabort

    similar mallocerrorabort not abort in out of memory conditions, making more useful catch errors cause memory corruption. malloccorruptionabort set on 64-bit processes.


that said, i'd still use valgrind first.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -