summaryrefslogtreecommitdiffstats
path: root/test/secmemtest.c
blob: 0ec3b9257188b1cbb01a214e01c8634a5b93f0a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <openssl/crypto.h>

int main(int argc, char **argv)
{
#if defined(OPENSSL_SYS_LINUX) || defined(OPENSSL_SYS_UNIX)
    char *p = NULL, *q = NULL;

    if (!CRYPTO_secure_malloc_init(4096, 32)) {
        perror("failed");
        return 1;
    }
    p = OPENSSL_secure_malloc(20);
    if (!CRYPTO_secure_allocated(p)) {
        perror("failed 1");
        return 1;
    }
    q = OPENSSL_malloc(20);
    if (CRYPTO_secure_allocated(q)) {
        perror("failed 1");
        return 1;
    }
    CRYPTO_secure_free(p);
    CRYPTO_free(q);
    CRYPTO_secure_malloc_done();
#else
    /* Should fail. */
    if (CRYPTO_secure_malloc_init(4096, 32)) {
        perror("failed");
        return 1;
    }
#endif
    return 0;
}