diff --git a/libraries/AP_Common/c++.cpp b/libraries/AP_Common/c++.cpp index 8ab798744f..8509f25bda 100644 --- a/libraries/AP_Common/c++.cpp +++ b/libraries/AP_Common/c++.cpp @@ -84,8 +84,35 @@ void operator delete[](void * ptr) if (ptr) free(ptr); } +#ifdef CYGWIN_BUILD +/* + wrapper around malloc to ensure all memory is initialised as zero + cygwin needs to wrap _malloc_r + */ +#undef _malloc_r +extern "C" { + void *__wrap__malloc_r(_reent *r, size_t size); + void *__real__malloc_r(_reent *r, size_t size); + void *_malloc_r(_reent *r, size_t size); +} +void *__wrap__malloc_r(_reent *r, size_t size) +{ + void *ret = __real__malloc_r(r, size); + if (ret != nullptr) { + memset(ret, 0, size); + } + return ret; +} +void *_malloc_r(_reent *x, size_t size) +{ + void *ret = __real__malloc_r(x, size); + if (ret != nullptr) { + memset(ret, 0, size); + } + return ret; +} -#if CONFIG_HAL_BOARD != HAL_BOARD_CHIBIOS +#elif CONFIG_HAL_BOARD != HAL_BOARD_CHIBIOS /* wrapper around malloc to ensure all memory is initialised as zero ChibiOS has its own wrapper