mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-11-27 06:22:06 +00:00
Initialize allocated memory to garbage
for debug builds.
This commit is contained in:
parent
62b38b1c66
commit
a94bc82a3c
3 changed files with 30 additions and 4 deletions
|
@ -195,6 +195,29 @@ fluid_log(int level, const char *fmt, ...)
|
|||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
void* fluid_alloc(size_t len)
|
||||
{
|
||||
void* ptr = malloc(len);
|
||||
|
||||
#if defined(DEBUG) && !defined(_MSC_VER)
|
||||
// garbage initialize allocated memory for debug builds to ease reproducing
|
||||
// bugs like 44453ff23281b3318abbe432fda90888c373022b .
|
||||
//
|
||||
// MSVC++ already garbage initializes allocated memory by itself (debug-heap).
|
||||
//
|
||||
// 0xCC because
|
||||
// * it makes pointers reliably crash when dereferencing them,
|
||||
// * floating points are still some valid but insanely huge negative number, and
|
||||
// * if for whatever reason this allocated memory is executed, it'll trigger
|
||||
// INT3 (...at least on x86)
|
||||
if(ptr != NULL)
|
||||
{
|
||||
memset(ptr, 0xCC, len);
|
||||
}
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper for free() that satisfies at least C90 requirements.
|
||||
* Especially useful when using fluidsynth with programming languages that do not provide malloc() and free().
|
||||
|
|
|
@ -739,4 +739,6 @@ static FLUID_INLINE void *fluid_align_ptr(const void *ptr, unsigned int alignmen
|
|||
|
||||
#define FLUID_DEFAULT_ALIGNMENT (64U)
|
||||
|
||||
void* fluid_alloc(size_t len);
|
||||
|
||||
#endif /* _FLUID_SYS_H */
|
||||
|
|
|
@ -126,12 +126,13 @@ typedef void (*fluid_rvoice_function_t)(void *obj, const fluid_rvoice_param_t pa
|
|||
* SYSTEM INTERFACE
|
||||
*/
|
||||
|
||||
#define FLUID_MALLOC(_n) malloc(_n)
|
||||
#define FLUID_MALLOC(_n) fluid_alloc(_n)
|
||||
#define FLUID_REALLOC(_p,_n) realloc(_p,_n)
|
||||
#define FLUID_NEW(_t) (_t*)malloc(sizeof(_t))
|
||||
#define FLUID_ARRAY_ALIGNED(_t,_n,_a) (_t*)malloc((_n)*sizeof(_t) + ((unsigned int)_a - 1u))
|
||||
#define FLUID_ARRAY(_t,_n) FLUID_ARRAY_ALIGNED(_t,_n,1u)
|
||||
#define FLUID_FREE(_p) fluid_free(_p)
|
||||
|
||||
#define FLUID_NEW(_t) (_t*)FLUID_MALLOC(sizeof(_t))
|
||||
#define FLUID_ARRAY_ALIGNED(_t,_n,_a) (_t*)FLUID_MALLOC((_n)*sizeof(_t) + ((unsigned int)_a - 1u))
|
||||
#define FLUID_ARRAY(_t,_n) FLUID_ARRAY_ALIGNED(_t,_n,1u)
|
||||
#define FLUID_FOPEN(_f,_m) fopen(_f,_m)
|
||||
#define FLUID_FCLOSE(_f) fclose(_f)
|
||||
#define FLUID_FREAD(_p,_s,_n,_f) fread(_p,_s,_n,_f)
|
||||
|
|
Loading…
Reference in a new issue