/src/opensips/mem/common.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * shared code between all memory allocators |
3 | | * |
4 | | * Copyright (C) 2019 OpenSIPS Solutions |
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 | | #include <strings.h> |
24 | | |
25 | | #include "common.h" |
26 | | #include "../dprint.h" |
27 | | |
28 | | enum osips_mm mem_allocator = MM_Q_MALLOC_DBG; |
29 | | |
30 | | /* returns -1 if @mm_name is unrecognized */ |
31 | | int set_global_mm(const char *mm_name) |
32 | 0 | { |
33 | | #ifdef INLINE_ALLOC |
34 | | LM_NOTICE("this is an inlined allocator build (see opensips -V), " |
35 | | "cannot set a custom memory allocator (%s)\n", mm_name); |
36 | | return 0; |
37 | | #endif |
38 | |
|
39 | 0 | if (parse_mm(mm_name, &mem_allocator) < 0) |
40 | 0 | return -1; |
41 | | |
42 | 0 | return 0; |
43 | 0 | } |
44 | | |
45 | | /* returns -1 if @mm_name is unrecognized */ |
46 | | int parse_mm(const char *mm_name, enum osips_mm *mm) |
47 | 0 | { |
48 | 0 | if (!strcasecmp(mm_name, "F_MALLOC")) { |
49 | 0 | *mm = MM_F_MALLOC; |
50 | 0 | return 0; |
51 | 0 | } |
52 | | |
53 | 0 | if (!strcasecmp(mm_name, "Q_MALLOC")) { |
54 | 0 | *mm = MM_Q_MALLOC; |
55 | 0 | return 0; |
56 | 0 | } |
57 | | |
58 | 0 | if (!strcasecmp(mm_name, "HP_MALLOC")) { |
59 | 0 | *mm = MM_HP_MALLOC; |
60 | 0 | return 0; |
61 | 0 | } |
62 | | |
63 | 0 | if (!strcasecmp(mm_name, "F_PARALLEL_MALLOC")) { |
64 | 0 | *mm = MM_F_PARALLEL_MALLOC; |
65 | 0 | return 0; |
66 | 0 | } |
67 | | |
68 | | #ifdef DBG_MALLOC |
69 | | if (!strcasecmp(mm_name, "F_MALLOC_DBG")) { |
70 | | *mm = MM_F_MALLOC_DBG; |
71 | | return 0; |
72 | | } |
73 | | |
74 | | if (!strcasecmp(mm_name, "Q_MALLOC_DBG")) { |
75 | | *mm = MM_Q_MALLOC_DBG; |
76 | | return 0; |
77 | | } |
78 | | |
79 | | if (!strcasecmp(mm_name, "HP_MALLOC_DBG")) { |
80 | | *mm = MM_HP_MALLOC_DBG; |
81 | | return 0; |
82 | | } |
83 | | |
84 | | if (!strcasecmp(mm_name, "F_PARALLEL_MALLOC_DBG")) { |
85 | | *mm = MM_F_PARALLEL_MALLOC_DBG; |
86 | | return 0; |
87 | | } |
88 | | #endif |
89 | | |
90 | 0 | return -1; |
91 | 0 | } |