Merge pull request #8620 from davidhorstmann-arm/fix-selftest-doublefree-2.28

[Backport 2.28] Fix potential double-free in calloc selftest
diff --git a/programs/test/selftest.c b/programs/test/selftest.c
index 2b78a8c..b9ba1e4 100644
--- a/programs/test/selftest.c
+++ b/programs/test/selftest.c
@@ -83,6 +83,7 @@
         if (verbose) {
             mbedtls_printf("  CALLOC(0,1): passed (same non-null)\n");
         }
+        empty2 = NULL;
     } else {
         if (verbose) {
             mbedtls_printf("  CALLOC(0,1): passed (distinct non-null)\n");
@@ -107,6 +108,7 @@
         if (verbose) {
             mbedtls_printf("  CALLOC(1,0): passed (same non-null)\n");
         }
+        empty2 = NULL;
     } else {
         if (verbose) {
             mbedtls_printf("  CALLOC(1,0): passed (distinct non-null)\n");
@@ -123,6 +125,7 @@
             mbedtls_printf("  CALLOC(1): failed (same buffer twice)\n");
         }
         ++failures;
+        buffer2 = NULL;
     } else {
         if (verbose) {
             mbedtls_printf("  CALLOC(1): passed\n");