{"id":21094468,"url":"https://github.com/d99kris/heapusage","last_synced_at":"2025-04-06T09:11:17.425Z","repository":{"id":19681032,"uuid":"87640153","full_name":"d99kris/heapusage","owner":"d99kris","description":"Find memory leaks in Linux and macOS applications","archived":false,"fork":false,"pushed_at":"2025-03-29T09:25:48.000Z","size":634,"stargazers_count":100,"open_issues_count":1,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T08:11:58.120Z","etag":null,"topics":["heap","linux","macos","memory-analysis","memory-leak","memory-leak-detection"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d99kris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-08T14:35:26.000Z","updated_at":"2025-03-29T09:25:52.000Z","dependencies_parsed_at":"2024-06-01T10:31:54.153Z","dependency_job_id":"aa2c1539-f39f-4e69-ba07-07f1aad0a96c","html_url":"https://github.com/d99kris/heapusage","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d99kris%2Fheapusage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d99kris%2Fheapusage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d99kris%2Fheapusage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d99kris%2Fheapusage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d99kris","download_url":"https://codeload.github.com/d99kris/heapusage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457803,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heap","linux","macos","memory-analysis","memory-leak","memory-leak-detection"],"created_at":"2024-11-19T22:17:36.487Z","updated_at":"2025-04-06T09:11:17.402Z","avatar_url":"https://github.com/d99kris.png","language":"C++","readme":"Heapusage\n=========\n\n| **Linux** | **Mac** |\n|-----------|---------|\n| [![Linux](https://github.com/d99kris/heapusage/workflows/Linux/badge.svg)](https://github.com/d99kris/heapusage/actions?query=workflow%3ALinux) | [![macOS](https://github.com/d99kris/heapusage/workflows/macOS/badge.svg)](https://github.com/d99kris/heapusage/actions?query=workflow%3AmacOS) |\n\nHeapusage is a light-weight tool for finding heap memory errors in Linux and\nmacOS applications. It provides a small subset of Valgrind's memcheck\nfunctionality, and can be a useful alternative to it for debugging memory\nleaks in certain scenarios such as:\n- Large complex applications which cannot be run at Valgrind slowdown speed\n- Embedded systems with CPU architectures not supported by Valgrind\n\nLike Valgrind, it is recommended to run Heapusage on a debug build of the\napplication to be analyzed.\n\nWhile Heapusage has less performance impact than Valgrind, its analysis is\nless precise. It may report leaks originating from system libraries (e.g.\nlibc functions like `printf()`) that might be free'd when the system library\nis being cleaned up.\n\nExample Usage\n=============\n\n    $ heapusage ./ex001\n    ==2933== Heapusage - https://github.com/d99kris/heapusage\n    ==2933== \n    ==2933== HEAP SUMMARY:\n    ==2933==     in use at exit: 12221 bytes in 4 blocks\n    ==2933==   total heap usage: 5 allocs, 1 frees, 13332 bytes allocated\n    ==2933==    peak heap usage: 13332 bytes allocated\n    ==2933== \n    ==2933== 6666 bytes in 3 block(s) are lost, originally allocated at:\n    ==2933==    at 0x00007fd04d062c88: malloc (humain.cpp:154)\n    ==2933==    at 0x00005611e856c1a4: main (ex001.c:29)\n    ==2933==    at 0x00007fd04ce470b3: __libc_start_main\n    ==2933==    at 0x00005611e856c0ae: _start\n    ==2933== \n    ==2933== 5555 bytes in 1 block(s) are lost, originally allocated at:\n    ==2933==    at 0x00007fd04d062c88: malloc (humain.cpp:154)\n    ==2933==    at 0x00005611e856c17f: main (ex001.c:19)\n    ==2933==    at 0x00007fd04ce470b3: __libc_start_main\n    ==2933==    at 0x00005611e856c0ae: _start\n    ==2933== \n    ==2933== LEAK SUMMARY:\n    ==2933==    definitely lost: 12221 bytes in 4 blocks\n    ==2933== \n\nSupported Platforms\n===================\nHeapusage is primarily developed and tested on Linux, but basic\nfunctionality should work in macOS as well. Current version has been tested on:\n- macOS Big Sur 11.0\n- Ubuntu 20.04 LTS\n\nLimitation: On macOS this tool relies on code injection using\nDYLD_INSERT_LIBRARIES, which generally does not work with third-party\napplications in a standard system. Using it on (your own) applications built\nfrom source should work fine though.\n\nInstallation\n============\nPre-requisites (Ubuntu):\n\n    sudo apt install git cmake build-essential\n\nOptional pre-requisite for source filename/line-number in callstacks (Ubuntu):\n\n    sudo apt install binutils-dev\n\nDownload the source code:\n\n    git clone https://github.com/d99kris/heapusage \u0026\u0026 cd heapusage\n\nBuild:\n\n    mkdir -p build \u0026\u0026 cd build \u0026\u0026 cmake .. \u0026\u0026 make -s\n\nOptionally install in system:\n\n    sudo make install\n\nUsage\n=====\nGeneral usage syntax:\n\n    heapusage [-d] [-m minsize] [-n] [-o path] [-t tools] PROG [ARGS..]\n    heapusage --help\n    heapusage --version\n\nOptions:\n\n    -d     debug mode, running program through debugger\n\n    -m \u003cminsize\u003e\n           min alloc size to enable analysis for (default 0)\n\n    -n     no symbol lookup (faster)\n\n    -o \u003cpath\u003e\n           write output to specified file path, instead of stderr\n\n    -s \u003cSIG\u003e\n           enable on-demand logging when signalled SIG signal\n\n    -t \u003ctools\u003e\n           analysis tools to use (default \"leak\")\n\n    PROG   program to run and analyze\n\n    [ARGS] optional arguments to the program\n\n    --help display this help and exit\n\n    --version\n           output version information and exit\n\nSupported tools (for option -t):\n\n    all    enables all supported tools below\n\n    double-free\n           detect free'ing of buffers already free'd\n\n    leak   detect memory allocations never free'd\n\n    overflow\n           detect buffer overflows, i.e. access beyond allocated memory\n\n    use-after-free\n           detect access to free'd memory buffers\n\nExamples:\n\n    heapusage -t leak,overflow -m 2048 ./ex001\n           analyze heap allocations of minimum 2048 bytes for leaks and overflows.\n\n    heapusage -t all -m 0 ./ex002\n           analyze heap allocations of any size with all tools.\n\nOutput Format\n=============\nExample output:\n\n    ==2933== Heapusage - https://github.com/d99kris/heapusage\n    ==2933== \n    ==2933== HEAP SUMMARY:\n    ==2933==     in use at exit: 12221 bytes in 4 blocks\n    ==2933==   total heap usage: 5 allocs, 1 frees, 13332 bytes allocated\n    ==2933==    peak heap usage: 13332 bytes allocated\n    ==2933== \n    ==2933== 6666 bytes in 3 block(s) are lost, originally allocated at:\n    ==2933==    at 0x00007fd04d062c88: malloc (humain.cpp:154)\n    ==2933==    at 0x00005611e856c1a4: main (ex001.c:29)\n    ==2933==    at 0x00007fd04ce470b3: __libc_start_main\n    ==2933==    at 0x00005611e856c0ae: _start\n    ==2933== \n    ==2933== 5555 bytes in 1 block(s) are lost, originally allocated at:\n    ==2933==    at 0x00007fd04d062c88: malloc (humain.cpp:154)\n    ==2933==    at 0x00005611e856c17f: main (ex001.c:19)\n    ==2933==    at 0x00007fd04ce470b3: __libc_start_main\n    ==2933==    at 0x00005611e856c0ae: _start\n    ==2933== \n    ==2933== LEAK SUMMARY:\n    ==2933==    definitely lost: 12221 bytes in 4 blocks\n    ==2933== \n\nSource code filename and line numbers are only supported on Linux, when package\nbinutils-dev is available. On macOS one can use atos to determine source code\ndetails.\n\nAdvanced Usage\n==============\nOn-demand report can be requested by utilizing the `-s` flag and specifying a\nsignal, and the sending the signal to the process. Example:\n\n    ./build/heapusage -s SIGUSR1 -t all -m 0 -o hu.txt nano\n    kill -s SIGUSR1 $(pidof nano)\n\nPrograms can also link libheapusage and call `hu_report()` for an on-demand\nreport, see `tests/ex007.cpp` for an example.\n\nNote that on-demand reporting will reflect the state when they are used, and\nwill thus report memory currently in use that might still be released before\nthe program exits, and therefore not necessarily constitute a memory leak.\n\nHeapusage uses a default call stack limit of 20 frames per call stack. It is\npossible to change this value at build time by using the `HU_MAX_CALL_STACK`\nCMake variable.\n\nTechnical Details\n=================\nHeapusage intercepts calls to malloc/free/calloc/realloc and logs each memory\nallocation and free. For overflow and use-after-free it uses protected memory\npages using `mprotect()` to detect writing outside valid allocations.\n\nLimitations\n===========\nHeapusage does currently not intercept calls to:\n- aligned_alloc\n- malloc_usable_size\n- memalign\n- posix_memalign\n- pvalloc\n- valloc\n\nThird-party Libraries\n---------------------\nHeapusage is implemented in C++. Its source tree includes the source code of the\nfollowing third-party libraries:\n\n- [backward-cpp](https://github.com/bombela/backward-cpp) -\n  Copyright 2013 Google Inc - [MIT License](/ext/backward-cpp/LICENSE.txt)\n\nAlternatives\n============\nThere are many heap memory debuggers available for Linux and macOS, for\nexample:\n\n- Address Sanitizer / Leak Sanitizer\n- Electric Fence\n- Mtrace\n- Valgrind\n\nLicense\n=======\nHeapusage is distributed under the BSD 3-Clause license. See LICENSE file.\n\nKeywords\n========\nlinux, macos, heap usage, finding memory leaks, alternative to valgrind.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd99kris%2Fheapusage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd99kris%2Fheapusage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd99kris%2Fheapusage/lists"}