2 * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 #include <openssl/bio.h>
12 #include <openssl/crypto.h>
17 * We use a proper main function here instead of the custom main from the
18 * test framework because the CRYPTO_mem_leaks_fp function cannot be called
19 * a second time without trying to use a null pointer. The test framework
20 * calls this function as part of its close down.
22 * A work around is to call putenv("OPENSSL_DEBUG_MEMORY=0"); before exiting
23 * but that is worse than avoiding the test framework's main.
26 int main(int argc, char *argv[])
28 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
33 p = getenv("OPENSSL_DEBUG_MEMORY");
34 if (p != NULL && strcmp(p, "on") == 0)
35 CRYPTO_set_mem_debug(1);
36 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
38 lost = OPENSSL_malloc(3);
42 if (argv[1] && strcmp(argv[1], "freeit") == 0) {
47 noleak = CRYPTO_mem_leaks_fp(stderr);
48 /* If -1 return value something bad happened */
49 if (!TEST_int_ne(noleak, -1))
52 return TEST_int_eq(lost != NULL, noleak == 0) ? EXIT_SUCCESS : EXIT_FAILURE;