Fix memory leak reporting.
authorDr. Stephen Henson <steve@openssl.org>
Sun, 8 Feb 2015 13:14:05 +0000 (13:14 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 9 Feb 2015 12:53:36 +0000 (12:53 +0000)
Free up bio_err after memory leak data has been printed to it.

In int_free_ex_data if ex_data is NULL there is nothing to free up
so return immediately and don't reallocate it.
Reviewed-by: Tim Hudson <tjh@openssl.org>
apps/openssl.c
crypto/ex_data.c

index 50c8275a4e58ac5aa1da9177351cdc4fc9f44cb0..e070a444a5b9472004ba610bf65e26bc0dbef13d 100644 (file)
@@ -423,10 +423,6 @@ int main(int Argc, char *ARGV[])
     if (arg.data != NULL)
         OPENSSL_free(arg.data);
 
-    if (bio_err != NULL) {
-        BIO_free(bio_err);
-        bio_err = NULL;
-    }
 #if defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64)
     /* Free any duplicate Argv[] storage. */
     if (free_Argv) {
@@ -435,6 +431,10 @@ int main(int Argc, char *ARGV[])
 #endif
     apps_shutdown();
     CRYPTO_mem_leaks(bio_err);
+    if (bio_err != NULL) {
+        BIO_free(bio_err);
+        bio_err = NULL;
+    }
 
     OPENSSL_EXIT(ret);
 }
index 4caddcebb4d049e3c87cbfb799e287f9097ce28d..d55985ba0aed6d5a6baacd5a06f68018a5a4a3a4 100644 (file)
@@ -500,6 +500,8 @@ static void int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
     EX_CLASS_ITEM *item;
     void *ptr;
     CRYPTO_EX_DATA_FUNCS **storage = NULL;
+    if (ex_data == NULL)
+        return;
     if ((item = def_get_class(class_index)) == NULL)
         return;
     CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);