From af7ba6955e6327f7999b0744716b05c260da6892 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 28 Feb 2012 14:49:47 -0500 Subject: [PATCH] Check for NULL return on win32 mm_calloc, and set ENOMEM. (It looks like windows doesn't set ENOMEM on overflow from calloc.) --- event.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/event.c b/event.c index bdcb8cd7..d9fa1abc 100644 --- a/event.c +++ b/event.c @@ -2827,8 +2827,15 @@ event_mm_calloc_(size_t count, size_t size) p = _mm_malloc_fn(sz); if (p) return memset(p, 0, sz); - } else - return calloc(count, size); + } else { + void *p = calloc(count, size); +#ifdef _WIN32 + /* Windows calloc doesn't reliably set ENOMEM */ + if (p == NULL) + goto error; +#endif + return p; + } error: errno = ENOMEM; -- 2.40.0