Module: kamailio Branch: master Commit: bc06c9f9ca546a6892c9a59f10fd0a963b46c737 URL: https://github.com/kamailio/kamailio/commit/bc06c9f9ca546a6892c9a59f10fd0a96...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2021-09-06T15:23:17+02:00
misctest: added memory module parameter
- control if it should do initialization for memory testing
---
Modified: src/modules/misctest/doc/misctest_params.xml Modified: src/modules/misctest/misctest_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/bc06c9f9ca546a6892c9a59f10fd0a96... Patch: https://github.com/kamailio/kamailio/commit/bc06c9f9ca546a6892c9a59f10fd0a96...
---
diff --git a/src/modules/misctest/doc/misctest_params.xml b/src/modules/misctest/doc/misctest_params.xml index 9bb0a10bfa..db19e29a26 100644 --- a/src/modules/misctest/doc/misctest_params.xml +++ b/src/modules/misctest/doc/misctest_params.xml @@ -12,6 +12,25 @@ </sectioninfo> <title>Parameters</title>
+ <section id="misctest.p.memory"> + <title><varname>memory</varname></title> + <para> + Initialize for memory testing. Set it to 1 to prepare the memory + testing. + </para> + <para> + Default: 0 (off). + </para> + <example> + <title> + Set <varname>memory</varname> in the config file + </title> + <programlisting> +modparam("misctest", "memory", 1) + </programlisting> + </example> + </section> + <section id="misctest.p.mem_check_content"> <title><varname>mem_check_content</varname></title> <para> diff --git a/src/modules/misctest/misctest_mod.c b/src/modules/misctest/misctest_mod.c index e26320ef93..2ce3187812 100644 --- a/src/modules/misctest/misctest_mod.c +++ b/src/modules/misctest/misctest_mod.c @@ -37,6 +37,7 @@ static int mt_mem_free_f(struct sip_msg *, char *, char *); static int mod_init(void); static void mod_destroy(void);
+static int misctest_memory = 0;
/* clang-format off */ static cmd_export_t cmds[]={ @@ -87,6 +88,7 @@ static rpc_export_t mt_rpc[];
/* clang-format off */ static param_export_t params[]={ + {"memory", PARAM_INT, &misctest_memory}, {"mem_check_content", PARAM_INT, &default_mt_cfg.mem_check_content}, {0,0,0} }; @@ -172,21 +174,23 @@ static int mod_init(void) goto error; }
- alloc_lst = shm_malloc(sizeof(*alloc_lst)); - if(alloc_lst == 0) - goto error; - alloc_lst->chunks = 0; - atomic_set_long(&alloc_lst->size, 0); - atomic_set_int(&alloc_lst->no, 0); - if(lock_init(&alloc_lst->lock) == 0) - goto error; - rndt_lst = shm_malloc(sizeof(*rndt_lst)); - if(rndt_lst == 0) - goto error; - rndt_lst->tests = 0; - atomic_set_int(&rndt_lst->last_id, 0); - if(lock_init(&rndt_lst->lock) == 0) - goto error; + if(misctest_memory!=0) { + alloc_lst = shm_malloc(sizeof(*alloc_lst)); + if(alloc_lst == 0) + goto error; + alloc_lst->chunks = 0; + atomic_set_long(&alloc_lst->size, 0); + atomic_set_int(&alloc_lst->no, 0); + if(lock_init(&alloc_lst->lock) == 0) + goto error; + rndt_lst = shm_malloc(sizeof(*rndt_lst)); + if(rndt_lst == 0) + goto error; + rndt_lst->tests = 0; + atomic_set_int(&rndt_lst->last_id, 0); + if(lock_init(&rndt_lst->lock) == 0) + goto error; + } return 0; error: return -1; @@ -195,17 +199,19 @@ static int mod_init(void)
static void mod_destroy() { - if(rndt_lst) { - mem_destroy_all_tests(); - lock_destroy(&rndt_lst->lock); - shm_free(rndt_lst); - rndt_lst = 0; - } - if(alloc_lst) { - mem_unleak(-1); - lock_destroy(&alloc_lst->lock); - shm_free(alloc_lst); - alloc_lst = 0; + if(misctest_memory!=0) { + if(rndt_lst) { + mem_destroy_all_tests(); + lock_destroy(&rndt_lst->lock); + shm_free(rndt_lst); + rndt_lst = 0; + } + if(alloc_lst) { + mem_unleak(-1); + lock_destroy(&alloc_lst->lock); + shm_free(alloc_lst); + alloc_lst = 0; + } } }