Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
malloc_dbg.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file that contains macros used to replace malloc/calloc and free.
4  * @details
5  * Macros malloc, calloc and free respectively calls malloc_dbg, calloc_dbg and free_dbg.
6  * malloc_dbg and calloc_dbg allocates memory using the "real" malloc and calloc and store
7  * the pointer returned (with additional informations) in a linked list.
8  * Thanks to this linked list, it is possible to check memory leaks.
9  * @author [tinouduart33](https://github.com/tinouduart33)
10  * @see malloc_dbg.c
11  */
12 
13 #ifndef MALLOC_DBG_H
14 #define MALLOC_DBG_H
15 
16  /** This macro replace the standard malloc function with malloc_dbg.
17  * */
18 #define malloc(bytes) malloc_dbg(bytes, __LINE__, __FILE__, __FUNCTION__)
19 
20  /** This macro replace the standard calloc function with calloc_dbg.
21  * */
22 #define calloc(elemCount, elemSize) calloc_dbg(elemCount, elemSize, __LINE__, __FILE__, __FUNCTION__)
23 
24  /** This macro replace the standard free function with free_dbg.
25  * */
26 #define free(ptr) free_dbg(ptr)
27 
28 void* malloc_dbg(size_t bytes, int line, const char* filename, const char* functionName);
29 
30 void* calloc_dbg(size_t elementCount, size_t elementSize, int line, const char* filename, const char* functionName);
31 
32 void free_dbg(void* ptrToFree);
33 
34 void printLeaks(void);
35 
36 #endif /* MALLOC_DBG_H */
void * malloc_dbg(size_t bytes, int line, const char *filename, const char *functionName)
malloc_dbg function is a wrapper around the malloc function.
Definition: malloc_dbg.c:129
void free_dbg(void *ptrToFree)
free_dbg function is used to free the memory allocated to a pointer.
Definition: malloc_dbg.c:208
void printLeaks(void)
printLeaks function is used to print all the memory leaks.
Definition: malloc_dbg.c:264
void * calloc_dbg(size_t elementCount, size_t elementSize, int line, const char *filename, const char *functionName)
calloc_dbg function is a wrapper around the calloc function.
Definition: malloc_dbg.c:174