From 299246408d3442a3240ccf25ce31c08ecee64766 Mon Sep 17 00:00:00 2001 From: wu-leilei Date: Mon, 20 Dec 2021 10:14:35 +0800 Subject: [PATCH] fix mem_size overflow --- alloc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/alloc.h b/alloc.h index 34a05f4..89cb727 100644 --- a/alloc.h +++ b/alloc.h @@ -33,6 +33,11 @@ #include /* for size_t */ +#ifndef _WIN32 +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -55,6 +60,12 @@ void hiredisResetAllocators(void); extern hiredisAllocFuncs hiredisAllocFns; static inline void *hi_malloc(size_t size) { +#ifndef _WIN32 + struct sysinfo s_info; + int error; + if((error = sysinfo(&s_info)) < 0) return NULL; + if(s_info.totalram < size) return NULL; +#endif return hiredisAllocFns.mallocFn(size); } -- 2.23.0