Skip to content

LD_PRELOADable library for snooping on malloc and friends

Notifications You must be signed in to change notification settings

minutils/memsnoop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

memsnoop

Build Status

LD_PRELOADable library for snooping on malloc and friends

Wrapped functions

  • malloc
  • free
  • realloc
  • calloc
  • valloc
  • memalign
  • posix_memalign

Building and Basic Usage

cmake .
make
LD_PRELOAD=./libmemsnoop.so ls

Output sample

malloc(568) = 0x2257010 [568/1]

malloc(568) was called, returning a pointer to 0x2257010, there are currently 568 total bytes allocated in 1 allocation.

free(0x2257010) [0/0]

free(0x2257010) was called, freeing that chunk. Now there are no outstanding allocations.

Options

export result
MEMSNOOP_NO_PRINT Don't print out all allocations.
MEMSNOOP_NO_TRACK Don't track allocations. Tracking allocations is expensive but will catch errors like double free or calling realloc with a pointer that was not previously allocated.
MEMSNOOP_NO_ABORT Don't abort program when memory errors are detected. Full speed ahead!
MEMSNOOP_MMAP Use mmap instead of native memory allocator. All allocations will be followed by an extra page that is mprotect(PROT_NONE), so buffer overruns (at least to the next page boundary) and underruns will immediately segfault. Cannot be used with MEMSNOOP_NO_TRACK.
MEMSNOOP_CHECK Write the lucky byte 0xA1 to unallocated sections of memory pages. Check for this byte when memory is freed to verify no buffers have been overrun. Requires MEMSNOOP_MMAP.
Based on https://github.com/jtolds/malloc_instrumentation

About

LD_PRELOADable library for snooping on malloc and friends

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published