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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/*
* Copyright (C) 2020 Samsung Electronics. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/slab.h>
#include "ese_log.h"
#include "ese_memory.h"
#ifdef CONFIG_STAR_MEMORY_LEAK
#define MAX_MEMORY_ALLOC_NUM 100
void *alloc_list[MAX_MEMORY_ALLOC_NUM];
void *ese_malloc(size_t size)
{
int i = 0;
for (i = 0; i < MAX_MEMORY_ALLOC_NUM; i ++) {
if (alloc_list[i] == NULL) {
break;
}
}
if (i == MAX_MEMORY_ALLOC_NUM) {
LOG_E("<MEMORY> exceed alloc list size");
return NULL;
}
alloc_list[i] = kzalloc(size, GFP_KERNEL);
LOG_I("<MEMORY> kzalloc addr : %p, size : %u", alloc_list[i], (unsigned int)size);
return alloc_list[i];
}
void ese_free(void *ptr)
{
int i = 0;
for (i = 0; i < MAX_MEMORY_ALLOC_NUM; i ++) {
if (alloc_list[i] == ptr) {
break;
}
}
if (i == MAX_MEMORY_ALLOC_NUM) {
LOG_E("<MEMORY> failed to find memory in alloc list : %p", ptr);
return;
}
alloc_list[i] = NULL;
kfree((void *)ptr);
LOG_I("<MEMORY> free addr : %p", ptr);
}
void ese_alloc_list(void)
{
int i = 0;
for (i = 0; i < MAX_MEMORY_ALLOC_NUM; i ++) {
if (alloc_list[i] != NULL) {
LOG_E("<MEMORY> non free memory : %p", alloc_list[i]);
}
}
}
#endif
|