]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/memleaktest.c
Move rc5_asm_src file information to build.info files
[thirdparty/openssl.git] / test / memleaktest.c
CommitLineData
440e5d80 1/*
789dfc47 2 * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
bbd86bf5 3 *
909f1a2e 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
440e5d80
RS
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
bbd86bf5
RS
8 */
9
bbd86bf5
RS
10#include <string.h>
11#include <openssl/bio.h>
12#include <openssl/crypto.h>
13
789dfc47
P
14#include "testutil.h"
15
16/*
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.
21 *
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.
24 */
25
26int main(int argc, char *argv[])
bbd86bf5 27{
c2e27310 28#ifndef OPENSSL_NO_CRYPTO_MDEBUG
bbd86bf5
RS
29 char *p;
30 char *lost;
ec04e866 31 int noleak;
bbd86bf5
RS
32
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);
37
38 lost = OPENSSL_malloc(3);
789dfc47
P
39 if (!TEST_ptr(lost))
40 return EXIT_FAILURE;
bbd86bf5 41
c2e27310 42 if (argv[1] && strcmp(argv[1], "freeit") == 0) {
bbd86bf5 43 OPENSSL_free(lost);
c2e27310
VD
44 lost = NULL;
45 }
bbd86bf5 46
ec04e866
DSH
47 noleak = CRYPTO_mem_leaks_fp(stderr);
48 /* If -1 return value something bad happened */
789dfc47
P
49 if (!TEST_int_ne(noleak, -1))
50 return EXIT_FAILURE;
51
52 return TEST_int_eq(lost != NULL, noleak == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
bbd86bf5 53#else
789dfc47 54 return EXIT_SUCCESS;
bbd86bf5
RS
55#endif
56}