diff options
author | Viktor Dukhovni <openssl-users@dukhovni.org> | 2016-01-10 14:42:10 -0500 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2016-01-11 02:41:16 +0000 |
commit | c2e27310c790c0dd2f87dd420e65e0cca522ddb2 (patch) | |
tree | bda08e77fcbd3f993498ef5a4c7d9b551b0b47ed /test/memleaktest.c | |
parent | 3af45d9978c0bf6ce333e9666f41a03d41822d0c (diff) | |
download | openssl-new-c2e27310c790c0dd2f87dd420e65e0cca522ddb2.tar.gz |
Enable/disable crypto-mdebug just like other features
Also always abort() on leak failure.
Reviewed-by: Stephen Henson <steve@openssl.org>
Diffstat (limited to 'test/memleaktest.c')
-rw-r--r-- | test/memleaktest.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/test/memleaktest.c b/test/memleaktest.c index cccbcf6625..cdb61a3608 100644 --- a/test/memleaktest.c +++ b/test/memleaktest.c @@ -56,12 +56,23 @@ #include <string.h> #include <openssl/bio.h> #include <openssl/crypto.h> +#include <setjmp.h> + +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +static sigjmp_buf env; + +static void handler(int sig) +{ + siglongjmp(env, 1); +} +#endif int main(int argc, char **argv) { -#ifdef CRYPTO_MDEBUG +#ifndef OPENSSL_NO_CRYPTO_MDEBUG char *p; char *lost; + int aborted = 0; p = getenv("OPENSSL_DEBUG_MEMORY"); if (p != NULL && strcmp(p, "on") == 0) @@ -74,15 +85,19 @@ int main(int argc, char **argv) return 1; } - if (argv[1] && strcmp(argv[1], "freeit") == 0) + signal(SIGABRT, handler); + + if (argv[1] && strcmp(argv[1], "freeit") == 0) { OPENSSL_free(lost); + lost = NULL; + } - CRYPTO_mem_leaks_fp(stderr); - return 0; + if (sigsetjmp(env, 0) == 0) + CRYPTO_mem_leaks_fp(stderr); + else + aborted = 1; + return ((lost != NULL) ^ (aborted == 1)); #else - if (argv[1] && strcmp(argv[1], "freeit") == 0) - return 0; - fprintf(stderr, "Leak simulated\n"); - return 1; + return 0; #endif } |