mkernel 0.0.1
Micro-kernel framework, everything as a module
|
Memory leak tracker header. More...
#include "memtrack.h"
Go to the source code of this file.
Functions | |
void * | dbg_malloc (const size_t Size, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function) |
Malloc compatible standard allocation. More... | |
void | dbg_free (void *Ptr, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function) |
Free compatible standard memory release. More... | |
void * | dbg_calloc (const size_t NMemb, const size_t Size, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function) |
Allocate a table of item from the size of each and number. More... | |
void * | dbg_realloc (void *Ptr, const size_t Size, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function) |
Resize an already allocated and tracked block. More... | |
char * | dbg_strdup (const char *Ptr, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function) |
String duplication with allocation. More... | |
int | dbg_asprintf (char **p_Ptr, const char *p_Format, const char *File, const int Line, const char *CompilDate, const char *CompilTime, const char *Function,...) |
Build a formatted string with allocation. More... | |
Memory leak tracker header.
Originally inspired by "L'art du code", Steve Maguire, Microsoft Press
Definition in file memdbg.h.
int dbg_asprintf | ( | char ** | p_Ptr, |
const char * | p_Format, | ||
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function, | ||
... | |||
) |
Build a formatted string with allocation.
[in,out] | p_Ptr | : Pointer on the to be built string |
[in] | p_Format | : Pointer on the format string |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
[in] | ... | : Values referenced by the format string |
>=0 | number of chars in the output string (as strdup) |
-1 | in case of error (*p_Ptr contents is undefined) |
void * dbg_calloc | ( | const size_t | NMemb, |
const size_t | Size, | ||
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function | ||
) |
Allocate a table of item from the size of each and number.
Uses malloc to allocate and track the memory bloc. If allocation and tracking succeed, fill the memory block with zeros.
[in] | NMemb | : Item number in the table |
[in] | Size | : Item size in bytes |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
Address | if succeeded, |
NULL | if not possible. |
Definition at line 76 of file memdbg.c.
void dbg_free | ( | void * | Ptr, |
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function | ||
) |
Free compatible standard memory release.
If the Ptr value is not NULL, try to untrack it. If it can not be found in the tracked list, because it was not tracked, it was allocated by a non monitored function, the function abort the process for investigation (missing a monitoring macro/function in the tracker, bug in the tracker, allocation from an external non-instrumented library). If the Ptr value was tracked, found and removed from the list successfully, forward it to free for actual free.
[in] | Ptr | : Pointer on the memory to free |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
Definition at line 52 of file memdbg.c.
void * dbg_malloc | ( | const size_t | Size, |
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function | ||
) |
Malloc compatible standard allocation.
[in] | Size | : Requested size in bytes |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
Address | if succeeded, |
NULL | if not possible. |
Definition at line 25 of file memdbg.c.
void * dbg_realloc | ( | void * | Ptr, |
const size_t | Size, | ||
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function | ||
) |
Resize an already allocated and tracked block.
This function always uses malloc to allocate a new block and force an address change, and a data loss in case of shrink, which is the worst case scenario for realloc.
As for realloc, a NULL source pointer makes realloc act as malloc, and a new size set to 0 acts as free. The input pointer is left untouched but should not be used or freed anymore. It is always different than the return value. The input values referenced by the input pointer are not wiped.
This implementation can not be used if realloc is used to reduce a huge bloc in order to manage an OOM situation. Real realloc can succeed by actually downsizing the same memory block, inplace, but this implementation will fail because it first allocate a new block.
[in] | Ptr | : Pointer on the memory to resize |
[in] | Size | : New size in bytes |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
Address | if succeeded, |
NULL | if not possible. |
< Existing bloc size
< New block
Definition at line 102 of file memdbg.c.
char * dbg_strdup | ( | const char * | Ptr, |
const char * | File, | ||
const int | Line, | ||
const char * | CompilDate, | ||
const char * | CompilTime, | ||
const char * | Function | ||
) |
String duplication with allocation.
[in] | Ptr | : Pointer on the string to copy |
[in] | File | : Source file |
[in] | Line | : Source line number |
[in] | CompilDate | : File compilation date |
[in] | CompilTime | : File compilation time |
[in] | Function | : Source function name |
Address | if succeeded, |
NULL | if not possible. |
Copy address