mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +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>
32 lines
915 B
C
32 lines
915 B
C
/**
|
|
* @file
|
|
* @brief File used to test the malloc_dbg, calloc_dbg and free_dbg functions.
|
|
* @details
|
|
* This file only have a main function that calls malloc, calloc and free.
|
|
* When the program exits, memory leaks must be printed.
|
|
* @author [tinouduart33](https://github.com/tinouduart33)
|
|
* @see malloc_dbg.c, malloc_dbg.h
|
|
*/
|
|
|
|
#include <stdio.h> /// For IO operations if needed.
|
|
#include <stdlib.h> /// For the EXIT_SUCCESS macro and the "real" malloc, calloc and free functions.
|
|
#include "malloc_dbg.h" /// For the macros malloc, calloc and free and the malloc_dbg, calloc_dbg and free_dbg functions.
|
|
|
|
|
|
/**
|
|
* @brief Main function
|
|
* @param argc number of arguments (not used)
|
|
* @param argv list of arguments (not used)
|
|
* @returns 0 on exit
|
|
*/
|
|
int main(int argc, char* argv[])
|
|
{
|
|
int* iptr = malloc(10 * sizeof(int));
|
|
char* cptr = calloc(256, sizeof(char));
|
|
|
|
free(iptr);
|
|
// free(cptr);
|
|
|
|
return 0;
|
|
}
|