1 /* 2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #include <stdio.h> 11 #include <string.h> 12 #include <openssl/bio.h> 13 #include <openssl/crypto.h> 14 15 int main(int argc, char **argv) 16 { 17 #ifndef OPENSSL_NO_CRYPTO_MDEBUG 18 char *p; 19 char *lost; 20 int noleak; 21 22 p = getenv("OPENSSL_DEBUG_MEMORY"); 23 if (p != NULL && strcmp(p, "on") == 0) 24 CRYPTO_set_mem_debug(1); 25 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); 26 27 lost = OPENSSL_malloc(3); 28 if (lost == NULL) { 29 fprintf(stderr, "OPENSSL_malloc failed\n"); 30 return 1; 31 } 32 33 if (argv[1] && strcmp(argv[1], "freeit") == 0) { 34 OPENSSL_free(lost); 35 lost = NULL; 36 } 37 38 noleak = CRYPTO_mem_leaks_fp(stderr); 39 /* If -1 return value something bad happened */ 40 if (noleak == -1) 41 return 1; 42 return ((lost != NULL) ^ (noleak == 0)); 43 #else 44 return 0; 45 #endif 46 } 47