Commit 486404334c for openssl.org

commit 486404334cfb27f73d35289d3c3e883307860f25
Author: Eugene Syromiatnikov <esyr@openssl.org>
Date:   Mon Apr 27 10:44:53 2026 +0200

    test/{handshake-,load_key_certs_crls_,x509_}memfail.c: count allocs properly

    Memory allocation failure testing (and counting) is done both for malloc
    and realloc calls, so the sum of those ought to be reported.

    Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>

    Reviewed-by: Matt Caswell <matt@openssl.foundation>
    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    MergeDate: Thu Apr 30 06:59:07 2026
    (Merged from https://github.com/openssl/openssl/pull/30991)

diff --git a/test/handshake-memfail.c b/test/handshake-memfail.c
index 35119c8e93..7c560806ce 100644
--- a/test/handshake-memfail.c
+++ b/test/handshake-memfail.c
@@ -29,10 +29,11 @@
  * - rcount:   Number of reallocs counted
  * - fcount:   Number of frees counted
  * - scount:   Number of mallocs counted prior to workload
+ * - srcount:  Number of reallocs counted prior to workload
  */
 static char *cert = NULL;
 static char *privkey = NULL;
-static int mcount, rcount, fcount, scount;
+static int mcount, rcount, fcount, scount, srcount;

 /**
  * @brief Performs an SSL/TLS handshake between a test client and server.
@@ -135,15 +136,16 @@ static int test_report_alloc_counts(void)
     CRYPTO_get_alloc_counts(&mcount, &rcount, &fcount);
     /*
      * Report our memory allocations from the count run
-     * NOTE: We report a number of allocations to skip here
-     * (the scount value).  These are the allocations that took
-     * place while the test harness itself was getting setup
-     * (i.e. calling OPENSSL_init_crypto/etc).  We can't fail
+     * NOTE: We report a number of (re)allocations to skip here
+     * (the scount + srcount value).  These are the allocations
+     * that took place while the test harness itself was getting
+     * setup (i.e. calling OPENSSL_init_crypto/etc).  We can't fail
      * those allocations as they will cause the test to fail before
      * we have even run the workload.  So report them so we can
      * allow them to function before we start doing any real testing
      */
-    TEST_info("skip: %d count %d\n", scount, mcount - scount);
+    TEST_info("skip: %d count %d\n",
+        scount + srcount, mcount + rcount - scount - srcount);
     return 1;
 }

@@ -167,7 +169,7 @@ int setup_tests(void)
         goto err;

     if (strcmp(opmode, "count") == 0) {
-        CRYPTO_get_alloc_counts(&scount, &rcount, &fcount);
+        CRYPTO_get_alloc_counts(&scount, &srcount, &fcount);
         ADD_TEST(test_record_alloc_counts);
         ADD_TEST(test_report_alloc_counts);
     } else {
diff --git a/test/load_key_certs_crls_memfail.c b/test/load_key_certs_crls_memfail.c
index 94297c0019..6d6125c946 100644
--- a/test/load_key_certs_crls_memfail.c
+++ b/test/load_key_certs_crls_memfail.c
@@ -24,7 +24,7 @@
 char *default_config_file = NULL;

 static char *certfile = NULL;
-static int mcount, rcount, fcount, scount;
+static int mcount, rcount, fcount, scount, srcount;

 static int do_load_key_certs_crls(int allow_failure)
 {
@@ -60,7 +60,8 @@ static int test_alloc_failures(void)
 static int test_report_alloc_counts(void)
 {
     CRYPTO_get_alloc_counts(&mcount, &rcount, &fcount);
-    TEST_info("skip: %d count %d\n", scount, mcount - scount);
+    TEST_info("skip: %d count %d\n",
+        scount + srcount, mcount + rcount - scount - srcount);
     return 1;
 }

@@ -79,7 +80,7 @@ int setup_tests(void)
         goto err;

     if (strcmp(opmode, "count") == 0) {
-        CRYPTO_get_alloc_counts(&scount, &rcount, &fcount);
+        CRYPTO_get_alloc_counts(&scount, &srcount, &fcount);
         ADD_TEST(test_record_alloc_counts);
         ADD_TEST(test_report_alloc_counts);
     } else {
diff --git a/test/x509_memfail.c b/test/x509_memfail.c
index 5be192bd55..41b2c098dc 100644
--- a/test/x509_memfail.c
+++ b/test/x509_memfail.c
@@ -21,7 +21,7 @@
 #include "testutil.h"

 static char *certfile = NULL;
-static int mcount, rcount, fcount, scount;
+static int mcount, rcount, fcount, scount, srcount;

 static int do_x509(int allow_failure)
 {
@@ -91,15 +91,16 @@ static int test_report_alloc_counts(void)
     CRYPTO_get_alloc_counts(&mcount, &rcount, &fcount);
     /*
      * Report our memory allocations from the count run
-     * NOTE: We report a number of allocations to skip here
-     * (the scount value).  These are the allocations that took
-     * place while the test harness itself was getting setup
-     * (i.e. calling OPENSSL_init_crypto/etc).  We can't fail
+     * NOTE: We report a number of (re)allocations to skip here
+     * (the scount + srcount value).  These are the allocations
+     * that took place while the test harness itself was getting
+     * setup (i.e. calling OPENSSL_init_crypto/etc).  We can't fail
      * those allocations as they will cause the test to fail before
      * we have even run the workload.  So report them so we can
      * allow them to function before we start doing any real testing
      */
-    TEST_info("skip: %d count %d\n", scount, mcount - scount);
+    TEST_info("skip: %d count %d\n",
+        scount + srcount, mcount + rcount - scount - srcount);
     return 1;
 }

@@ -115,7 +116,7 @@ int setup_tests(void)
         goto err;

     if (strcmp(opmode, "count") == 0) {
-        CRYPTO_get_alloc_counts(&scount, &rcount, &fcount);
+        CRYPTO_get_alloc_counts(&scount, &srcount, &fcount);
         ADD_TEST(test_record_alloc_counts);
         ADD_TEST(test_report_alloc_counts);
     } else {