-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.c
53 lines (40 loc) · 1.11 KB
/
mem.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdlib.h>
#include <string.h>
#include "crypto.h"
# define osslargused(x) (void)x // from e_os.h
/*
* the following pointers may be changed as long as 'allow_customize' is set
*/
static int allow_customize = 1;
static void *(*malloc_impl)(size_t, const char *, int)
= CRYPTO_malloc;
static void (*free_impl)(void *, const char *, int)
= CRYPTO_free;
static int call_malloc_debug = 0;
void *CRYPTO_malloc(size_t num, const char *file, int line)
{
void *ret = NULL;
if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
return malloc_impl(num, file, line);
if (num <= 0)
return NULL;
allow_customize = 0;
osslargused(file); osslargused(line);
ret = malloc(num);
return ret;
}
void CRYPTO_free(void *str, const char *file, int line)
{
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
free(str);
}
void *CRYPTO_zalloc(size_t num, const char *file, int line)
{
void *ret = CRYPTO_malloc(num, file, line);
if (ret != NULL)
memset(ret, 0, num);
return ret;
}