https://github.com/refi64/noleak
An easy-to-use leak detector for C and C++
https://github.com/refi64/noleak
Last synced: 8 months ago
JSON representation
An easy-to-use leak detector for C and C++
- Host: GitHub
- URL: https://github.com/refi64/noleak
- Owner: refi64
- License: mit
- Created: 2014-08-09T20:52:17.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-09T22:11:34.000Z (almost 12 years ago)
- Last Synced: 2025-03-25T05:06:47.106Z (about 1 year ago)
- Language: C
- Size: 141 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
NoLeak
======
NoLeak is an easy-use leak detector for C and C++ programs.
Building
********
The build files are generated using `Bakefile `_. Unix users can just run `make`. Visual Studio users will find a solution file under `vsproj//noleak.sln`, replacing `` with your Visual Studio version. For instance, VS 2012 users would open `vsproj/2012/noleak.sln`.
C usage
*******
Replace calls to `malloc` with `NL_MALLOC`, calls to `free` with `NL_FREE`, calls to `calloc` with `NL_CALLOC`, and calls to `realloc` with `NL_REALLOC`. Then, call `noleak_init()` at the start of your program's main function and include `noleak.h` at the top of the file. For example, change this:
.. code:: c
int main()
{
int* p = malloc(4);
...
// forget to free p
return 0;
}
to this:
.. code:: c
#include
int main()
{
noleak_init();
int* p = NL_MALLOC(4);
...
return 0;
}
Now, all memory leaks will be printed on program exit. The program's output will look like this::
Leak #1 at test.c:main:6
Total leaks: 1
C++ usage
*********
With C++, replace calls to `new` with `new (NOLEAK)` and again include `noleak.h`. For instance:
.. code:: c++
#include
int main()
{
int* p = new (NOLEAK) int;
// forget to delete p
return 0;
}
There's no need to replace `delete` calls.