mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
3682694f76
* Add malloc, calloc and free wrappers to trace all of the allocations * Improve memory leak reporting when multiple allocations occurs in the same file at the same line. * Change directory name from 'debugging' to 'developer_tools' and added CMakeLists.txt, also change an include name to match a file name * Edit root CMakeLists.Txt * Update developer_tools/malloc_dbg.h Co-authored-by: David Leal <halfpacho@gmail.com> * Edit CMakeLists.txt to create a static library from malloc_dbg.c * Add comments for the includes * Change test.c name to test_malloc_dbg.c, also edit CMakeLists.txt to link malloc_dbg.a only to test_malloc_dbg. * Change comment style and change EXIT_SUCCESS to 0 * Fix typo in doxygen comments * Enhance comments * Apply suggestions from code review Co-authored-by: David Leal <halfpacho@gmail.com>
37 lines
1.3 KiB
C
37 lines
1.3 KiB
C
/**
|
|
* @file
|
|
* @brief Header file that contains macros used to replace malloc/calloc and free.
|
|
* @details
|
|
* Macros malloc, calloc and free respectively calls malloc_dbg, calloc_dbg and free_dbg.
|
|
* malloc_dbg and calloc_dbg allocates memory using the "real" malloc and calloc and store
|
|
* the pointer returned (with additional informations) in a linked list.
|
|
* Thanks to this linked list, it is possible to check memory leaks.
|
|
* @author [tinouduart33](https://github.com/tinouduart33)
|
|
* @see malloc_dbg.c
|
|
*/
|
|
|
|
#ifndef MALLOC_DBG_H
|
|
#define MALLOC_DBG_H
|
|
|
|
/** This macro replace the standard malloc function with malloc_dbg.
|
|
* */
|
|
#define malloc(bytes) malloc_dbg(bytes, __LINE__, __FILE__, __FUNCTION__)
|
|
|
|
/** This macro replace the standard calloc function with calloc_dbg.
|
|
* */
|
|
#define calloc(elemCount, elemSize) calloc_dbg(elemCount, elemSize, __LINE__, __FILE__, __FUNCTION__)
|
|
|
|
/** This macro replace the standard free function with free_dbg.
|
|
* */
|
|
#define free(ptr) free_dbg(ptr)
|
|
|
|
void* malloc_dbg(size_t bytes, int line, const char* filename, const char* functionName);
|
|
|
|
void* calloc_dbg(size_t elementCount, size_t elementSize, int line, const char* filename, const char* functionName);
|
|
|
|
void free_dbg(void* ptrToFree);
|
|
|
|
void printLeaks(void);
|
|
|
|
#endif /* MALLOC_DBG_H */
|