]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: dovecot-openssl-common - Make the allocators bit more in line with...
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 27 Dec 2023 19:29:43 +0000 (21:29 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 17 Jan 2024 08:23:46 +0000 (10:23 +0200)
src/lib-ssl-iostream/dovecot-openssl-common.c

index 49e8f707c5b374e70db8db2a05cc49ab2d6916df..ac617d2623cca4084ce282146908de87456d3207 100644 (file)
@@ -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;
 }