All Projects → d99kris → Heapusage

d99kris / Heapusage

Licence: bsd-3-clause
Find memory leaks in Linux and macOS applications

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Heapusage

Unityheapcrawler
Reflection based heap shapshot tool for Unity game engine
Stars: ✭ 91 (+71.7%)
Mutual labels:  heap, memory-leak
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (-45.28%)
Mutual labels:  memory-leak
Android interviews
🚀Everything you need to know to find a android job. 算法 / 面试题 / Android 知识点 🔥🔥🔥 总结不易,你的 star 是我最大的动力!
Stars: ✭ 510 (+862.26%)
Mutual labels:  heap
Dsa.js Data Structures Algorithms Javascript
🥞Data Structures and Algorithms explained and implemented in JavaScript + eBook
Stars: ✭ 6,251 (+11694.34%)
Mutual labels:  heap
Php Memory Profiler
Memory leak profiler for PHP
Stars: ✭ 544 (+926.42%)
Mutual labels:  memory-leak
Advanced Algorithms
100+ algorithms & data structures generically implemented in C#.
Stars: ✭ 752 (+1318.87%)
Mutual labels:  heap
Coding Interview Gym
leetcode.com , algoexpert.io solutions in python and swift
Stars: ✭ 451 (+750.94%)
Mutual labels:  heap
Heap Exploitation
This book on heap exploitation is a guide to understanding the internals of glibc's heap and various attacks possible on the heap structure.
Stars: ✭ 1,043 (+1867.92%)
Mutual labels:  heap
Cpputest
CppUTest unit testing and mocking framework for C/C++
Stars: ✭ 896 (+1590.57%)
Mutual labels:  memory-leak
Heap allocator
A simple heap memory allocator in ~200 lines.
Stars: ✭ 661 (+1147.17%)
Mutual labels:  heap
Memoscope.net
Dump and analyze .Net applications memory ( a gui for WinDbg and ClrMd )
Stars: ✭ 626 (+1081.13%)
Mutual labels:  memory-leak
Memleax
debugs memory leak of running process. Not maintained anymore, try `libleak` please.
Stars: ✭ 564 (+964.15%)
Mutual labels:  memory-leak
Js Leakage Patterns
🎯这是关于JavaScript内存泄露和CSS优化相关序列文章,相信你读完会有所收获的✈️
Stars: ✭ 756 (+1326.42%)
Mutual labels:  memory-leak
Heapify
The fastest JavaScript priority queue out there. Zero dependencies.
Stars: ✭ 520 (+881.13%)
Mutual labels:  heap
Windbg Cheat Sheet
A practical guide to analyze memory dumps of .Net applications by using Windbg
Stars: ✭ 43 (-18.87%)
Mutual labels:  memory-leak
Algorithms
CLRS study. Codes are written with golang.
Stars: ✭ 482 (+809.43%)
Mutual labels:  heap
Learningmasteringalgorithms C
Mastering Algorithms with C 《算法精解:C语言描述》源码及Xcode工程、Linux工程
Stars: ✭ 615 (+1060.38%)
Mutual labels:  heap
Leakcanary
A memory leak detection library for Android.
Stars: ✭ 27,029 (+50898.11%)
Mutual labels:  memory-leak
Main arena offset
A simple shell script to get main_arena offset of a given libc
Stars: ✭ 53 (+0%)
Mutual labels:  heap
Algorithms
Solved algorithms and data structures problems in many languages
Stars: ✭ 1,021 (+1826.42%)
Mutual labels:  heap

Heapusage

Linux Mac
Linux macOS

Heapusage is a light-weight tool for finding memory leaks in Linux and macOS applications. It provides a small but important subset of Valgrind's memcheck functionality, and can be a useful alternative to it for debugging memory leaks in certain scenarios such as:

  • Large complex applications which cannot be run at Valgrind slowdown speed
  • Embedded systems with CPU architectures not supported by Valgrind

Like Valgrind, it is recommended to run Heapusage on a debug build of the application to be analyzed.

While Heapusage has less performance impact than Valgrind, its analysis is less precise. It may report leaks originating from system libraries (e.g. libc functions like print()) that might be free'd when the system library is being cleaned up.

Example Usage

$ heapusage ./ex001
==22648== Heapusage - https://github.com/d99kris/heapusage
==22648== 
==22648== HEAP SUMMARY:
==22648==     in use at exit: 12221 bytes in 4 blocks
==22648==   total heap usage: 5 allocs, 1 frees, 13332 bytes allocated
==22648== 
==22648== 6666 bytes in 3 block(s) are lost, originally allocated at:
==22648==    at 0x00007fdca672199d: malloc + 49
==22648==    at 0x000000000040080d: main + 55
==22648==    at 0x00007fdca6376830: __libc_start_main + 240
==22648==    at 0x0000000000400709: _start + 41
==22648== 
==22648== 5555 bytes in 1 block(s) are lost, originally allocated at:
==22648==    at 0x00007fdca672199d: malloc + 49
==22648==    at 0x00000000004007e8: main + 18
==22648==    at 0x00007fdca6376830: __libc_start_main + 240
==22648==    at 0x0000000000400709: _start + 41
==22648== 
==22648== LEAK SUMMARY:
==22648==    definitely lost: 12221 bytes in 4 blocks
==22648== 

Supported Platforms

Heapusage is primarily developed and tested on Linux, but basic functionality should work in macOS / OS X as well. Current version has been tested on:

  • macOS Big Sur 11.0
  • Ubuntu 20.04 LTS

Limitation: On macOS this tool relies on code injection using DYLD_INSERT_LIBRARIES, which generally does not work with third-party applications in a standard system. Using it on (your own) applications built from source should work fine though.

Installation

Pre-requisites (Ubuntu):

sudo apt install git cmake build-essential

Download the source code:

git clone https://github.com/d99kris/heapusage && cd heapusage

Generate Makefile and build:

mkdir -p build && cd build && cmake .. && make -s

Optionally install in system:

sudo make install

Usage

General usage syntax:

heapusage [-d] [-f] [-m minsize] [-n] [-o path] PROG [ARGS..]
heapusage --help
heapusage --version

Options:

-d     debug mode, running program through debugger

-f     check for invalid free's (experimental)

-m <minsize>
       minimum leak in bytes for detailed reporting

-n     no symbol lookup (faster)

-o <path>
       write output to specified file path, instead of stderr

PROG   program to run and analyze

[ARGS] optional arguments to the program

--help display this help and exit

--version
       output version information and exit

Example running heapusage with test program 'ex001':

heapusage ./ex001

Output Format

Example output:

==22648== Heapusage - https://github.com/d99kris/heapusage
==22648== 
==22648== HEAP SUMMARY:
==22648==     in use at exit: 12221 bytes in 4 blocks
==22648==   total heap usage: 5 allocs, 1 frees, 13332 bytes allocated
==22648== 
==22648== 6666 bytes in 3 block(s) are lost, originally allocated at:
==22648==    at 0x00007fdca672199d: malloc + 49
==22648==    at 0x000000000040080d: main + 55
==22648==    at 0x00007fdca6376830: __libc_start_main + 240
==22648==    at 0x0000000000400709: _start + 41
==22648== 
==22648== 5555 bytes in 1 block(s) are lost, originally allocated at:
==22648==    at 0x00007fdca672199d: malloc + 49
==22648==    at 0x00000000004007e8: main + 18
==22648==    at 0x00007fdca6376830: __libc_start_main + 240
==22648==    at 0x0000000000400709: _start + 41
==22648== 
==22648== LEAK SUMMARY:
==22648==    definitely lost: 12221 bytes in 4 blocks
==22648== 

The corresponding file and line number of the stacktrace addresses can be determined using addr2line on Linux (the equivalent tool for macOS is atos):

$ addr2line -f -e ./ex001 0x000000000040080d
main
tests/ex001.c:29

Technical Details

Heapusage intercepts calls to malloc/free/etc and logs each memory allocation and free. At process termination it outputs logging of all allocations not free'd.

Alternatives

There are many memory leak checkers available for Linux and macOS, for example:

  • LeakSanitizer
  • Mtrace
  • Valgrind

License

Heapusage is distributed under the BSD 3-Clause license. See LICENSE file.

Keywords

linux, macos, heap usage, finding memory leaks, alternative to valgrind.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].