/src/opensips/lib/osips_malloc.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * OpenSIPS equivalent of the stdlib allocation functions |
3 | | * |
4 | | * Copyright (C) 2017 OpenSIPS Project |
5 | | * |
6 | | * This file is part of opensips, a free SIP server. |
7 | | * |
8 | | * opensips is free software; you can redistribute it and/or modify |
9 | | * it under the terms of the GNU General Public License as published by |
10 | | * the Free Software Foundation; either version 2 of the License, or |
11 | | * (at your option) any later version |
12 | | * |
13 | | * opensips is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU General Public License |
19 | | * along with this program; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | */ |
22 | | |
23 | | #ifndef __OSIPS_MALLOC_H__ |
24 | | #define __OSIPS_MALLOC_H__ |
25 | | |
26 | | #include "../mem/mem.h" |
27 | | #include "../mem/shm_mem.h" |
28 | | |
29 | | typedef void *(*osips_malloc_t)(size_t size); |
30 | | typedef void (*osips_free_t)(void *ptr); |
31 | | typedef void *(*osips_calloc_t)(size_t nmemb, size_t size); |
32 | | typedef void *(*osips_realloc_t)(void *ptr, size_t size); |
33 | | typedef char *(*osips_strdup_t)(const char *s); |
34 | | |
35 | | static inline void *osips_pkg_malloc(size_t size) |
36 | 0 | { |
37 | 0 | return pkg_malloc(size); |
38 | 0 | } Unexecuted instantiation: mi.c:osips_pkg_malloc Unexecuted instantiation: mod_fix.c:osips_pkg_malloc Unexecuted instantiation: transformations.c:osips_pkg_malloc Unexecuted instantiation: time_rec.c:osips_pkg_malloc Unexecuted instantiation: csv.c:osips_pkg_malloc Unexecuted instantiation: cJSON.c:osips_pkg_malloc |
39 | | |
40 | | static inline void osips_pkg_free(void *ptr) |
41 | 0 | { |
42 | 0 | pkg_free(ptr); |
43 | 0 | } Unexecuted instantiation: mi.c:osips_pkg_free Unexecuted instantiation: mod_fix.c:osips_pkg_free Unexecuted instantiation: transformations.c:osips_pkg_free Unexecuted instantiation: time_rec.c:osips_pkg_free Unexecuted instantiation: csv.c:osips_pkg_free Unexecuted instantiation: cJSON.c:osips_pkg_free |
44 | | |
45 | | static inline void *osips_pkg_calloc(size_t nmemb, size_t size) |
46 | 0 | { |
47 | 0 | void *p; |
48 | 0 |
|
49 | 0 | p = pkg_malloc(nmemb * size); |
50 | 0 | if (p) { |
51 | 0 | memset(p, '\0', nmemb * size); |
52 | 0 | } |
53 | 0 |
|
54 | 0 | return p; |
55 | 0 | } Unexecuted instantiation: mi.c:osips_pkg_calloc Unexecuted instantiation: mod_fix.c:osips_pkg_calloc Unexecuted instantiation: transformations.c:osips_pkg_calloc Unexecuted instantiation: time_rec.c:osips_pkg_calloc Unexecuted instantiation: csv.c:osips_pkg_calloc Unexecuted instantiation: cJSON.c:osips_pkg_calloc |
56 | | |
57 | | static inline void *osips_pkg_realloc(void *ptr, size_t size) |
58 | 0 | { |
59 | 0 | return pkg_realloc(ptr, size); |
60 | 0 | } Unexecuted instantiation: mi.c:osips_pkg_realloc Unexecuted instantiation: mod_fix.c:osips_pkg_realloc Unexecuted instantiation: transformations.c:osips_pkg_realloc Unexecuted instantiation: time_rec.c:osips_pkg_realloc Unexecuted instantiation: csv.c:osips_pkg_realloc Unexecuted instantiation: cJSON.c:osips_pkg_realloc |
61 | | |
62 | | static inline char *osips_pkg_strdup(const char *s) |
63 | 0 | { |
64 | 0 | char *rval; |
65 | 0 | int len; |
66 | 0 |
|
67 | 0 | len = strlen(s) + 1; |
68 | 0 | rval = pkg_malloc(len); |
69 | 0 | if (!rval) { |
70 | 0 | return NULL; |
71 | 0 | } |
72 | 0 |
|
73 | 0 | memcpy(rval, s, len); |
74 | 0 | return rval; |
75 | 0 | } Unexecuted instantiation: mi.c:osips_pkg_strdup Unexecuted instantiation: mod_fix.c:osips_pkg_strdup Unexecuted instantiation: transformations.c:osips_pkg_strdup Unexecuted instantiation: time_rec.c:osips_pkg_strdup Unexecuted instantiation: csv.c:osips_pkg_strdup Unexecuted instantiation: cJSON.c:osips_pkg_strdup |
76 | | |
77 | | static inline void *osips_shm_malloc(size_t size) |
78 | 0 | { |
79 | 0 | return shm_malloc(size); |
80 | 0 | } Unexecuted instantiation: mi.c:osips_shm_malloc Unexecuted instantiation: mod_fix.c:osips_shm_malloc Unexecuted instantiation: transformations.c:osips_shm_malloc Unexecuted instantiation: time_rec.c:osips_shm_malloc Unexecuted instantiation: csv.c:osips_shm_malloc Unexecuted instantiation: cJSON.c:osips_shm_malloc |
81 | | |
82 | | static inline void osips_shm_free(void *ptr) |
83 | 0 | { |
84 | 0 | shm_free(ptr); |
85 | 0 | } Unexecuted instantiation: mi.c:osips_shm_free Unexecuted instantiation: mod_fix.c:osips_shm_free Unexecuted instantiation: transformations.c:osips_shm_free Unexecuted instantiation: time_rec.c:osips_shm_free Unexecuted instantiation: csv.c:osips_shm_free Unexecuted instantiation: cJSON.c:osips_shm_free |
86 | | |
87 | | static inline void *osips_shm_calloc(size_t nmemb, size_t size) |
88 | 0 | { |
89 | 0 | void *p; |
90 | 0 |
|
91 | 0 | p = shm_malloc(nmemb * size); |
92 | 0 | if (p) { |
93 | 0 | memset(p, '\0', nmemb * size); |
94 | 0 | } |
95 | 0 |
|
96 | 0 | return p; |
97 | 0 | } Unexecuted instantiation: mi.c:osips_shm_calloc Unexecuted instantiation: mod_fix.c:osips_shm_calloc Unexecuted instantiation: transformations.c:osips_shm_calloc Unexecuted instantiation: time_rec.c:osips_shm_calloc Unexecuted instantiation: csv.c:osips_shm_calloc Unexecuted instantiation: cJSON.c:osips_shm_calloc |
98 | | |
99 | | static inline void *osips_shm_realloc(void *ptr, size_t size) |
100 | 0 | { |
101 | 0 | return shm_realloc(ptr, size); |
102 | 0 | } Unexecuted instantiation: mi.c:osips_shm_realloc Unexecuted instantiation: mod_fix.c:osips_shm_realloc Unexecuted instantiation: transformations.c:osips_shm_realloc Unexecuted instantiation: time_rec.c:osips_shm_realloc Unexecuted instantiation: csv.c:osips_shm_realloc Unexecuted instantiation: cJSON.c:osips_shm_realloc |
103 | | |
104 | | static inline char *osips_shm_strdup(const char *s) |
105 | 0 | { |
106 | 0 | char *rval; |
107 | 0 | int len; |
108 | 0 |
|
109 | 0 | len = strlen(s) + 1; |
110 | 0 | rval = shm_malloc(len); |
111 | 0 | if (!rval) { |
112 | 0 | return NULL; |
113 | 0 | } |
114 | 0 |
|
115 | 0 | memcpy(rval, s, len); |
116 | 0 | return rval; |
117 | 0 | } Unexecuted instantiation: mi.c:osips_shm_strdup Unexecuted instantiation: mod_fix.c:osips_shm_strdup Unexecuted instantiation: transformations.c:osips_shm_strdup Unexecuted instantiation: time_rec.c:osips_shm_strdup Unexecuted instantiation: csv.c:osips_shm_strdup Unexecuted instantiation: cJSON.c:osips_shm_strdup |
118 | | |
119 | | #endif /* __OSIPS_MALLOC_H__ */ |