From: Aki Tuomi Date: Wed, 27 Dec 2023 19:29:43 +0000 (+0200) Subject: lib-ssl-iostream: dovecot-openssl-common - Make the allocators bit more in line with... X-Git-Tag: 2.4.0~1851 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e23cd6f2b00e2adbe7b86289200c43effd69e7e;p=thirdparty%2Fdovecot%2Fcore.git lib-ssl-iostream: dovecot-openssl-common - Make the allocators bit more in line with libssl --- diff --git a/src/lib-ssl-iostream/dovecot-openssl-common.c b/src/lib-ssl-iostream/dovecot-openssl-common.c index 49e8f707c5..ac617d2623 100644 --- a/src/lib-ssl-iostream/dovecot-openssl-common.c +++ b/src/lib-ssl-iostream/dovecot-openssl-common.c @@ -27,12 +27,14 @@ static void *dovecot_openssl_malloc(size_t size, const char *u0 ATTR_UNUSED, int static void *dovecot_openssl_malloc(size_t size) #endif { + if (size == 0) + return NULL; /* this may be performance critical, so don't use i_malloc() or calloc() */ void *mem = malloc(size); - if (mem == NULL) { + if (unlikely(mem == NULL)) { i_fatal_status(FATAL_OUTOFMEM, - "OpenSSL: malloc(%zu): Out of memory", size); + "OpenSSL: malloc(%zu): Out of memory", size); } return mem; } @@ -43,10 +45,14 @@ static void *dovecot_openssl_realloc(void *ptr, size_t size, const char *u0 ATTR static void *dovecot_openssl_realloc(void *ptr, size_t size) #endif { + if (size == 0) { + free(ptr); + return NULL; + } void *mem = realloc(ptr, size); - if (mem == NULL) { + if (unlikely(mem == NULL)) { i_fatal_status(FATAL_OUTOFMEM, - "OpenSSL: realloc(%zu): Out of memory", size); + "OpenSSL: realloc(%zu): Out of memory", size); } return mem; }