Merge branch '2.0.x' into master

This commit is contained in:
derselbst 2019-10-05 16:55:10 +02:00
commit d80c704a7b
3 changed files with 29 additions and 4 deletions

View File

@ -192,6 +192,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().

View File

@ -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 */

View File

@ -181,12 +181,12 @@ typedef void (*fluid_rvoice_function_t)(void *obj, const fluid_rvoice_param_t pa
#endif
/* Memory allocation */
#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)
/* File access */
#define FLUID_FOPEN(_f,_m) fopen(_f,_m)