Commit 6e7ea5ce authored by Guido Casati's avatar Guido Casati Committed by Guido Casati

Fix memory leak in RCconfig_nr_parallel

* strdup() function is returning a malloced string
  which must be freed after use
* replace the strdup with direct use of strings to avoid heap allocation

> Direct leak of 23 byte(s) in 1 object(s) allocated from:
    > 0 0x7ffff745b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    > 1 0x555559e36f87 in RCconfig_nr_parallel /openair2/GNB_APP/gnb_config.c:2054
    > 2 0x555559e38ea3 in NRRCConfig /openair2/GNB_APP/gnb_config.c:2097
    > 3 0x555559155542 in get_options /executables/nr-softmodem.c:423
    > 4 0x555559155542 in main /executables/nr-softmodem.c:623
    > 5 0x7ffff5e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

> Direct leak of 14 byte(s) in 1 object(s) allocated from:
    > 0 0x7ffff745b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    > 1 0x555559e370c5 in RCconfig_nr_parallel /openair2/GNB_APP/gnb_config.c:2063
    > 2 0x555559e38ea3 in NRRCConfig /openair2/GNB_APP/gnb_config.c:2097
    > 3 0x555559155542 in get_options /executables/nr-softmodem.c:423
    > 4 0x555559155542 in main /executables/nr-softmodem.c:623
    > 5 0x7ffff5e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
parent bd721c3b
...@@ -2041,31 +2041,29 @@ int RCconfig_NR_NG(MessageDef *msg_p, uint32_t i) { ...@@ -2041,31 +2041,29 @@ int RCconfig_NR_NG(MessageDef *msg_p, uint32_t i) {
} }
int RCconfig_nr_parallel(void) { int RCconfig_nr_parallel(void) {
char *parallel_conf = NULL;
char *worker_conf = NULL;
extern char *parallel_config; extern char *parallel_config;
extern char *worker_config; extern char *worker_config;
paramdef_t ThreadParams[] = THREAD_CONF_DESC; paramdef_t ThreadParams[] = THREAD_CONF_DESC;
paramlist_def_t THREADParamList = {THREAD_CONFIG_STRING_THREAD_STRUCT,NULL,0}; paramlist_def_t THREADParamList = {THREAD_CONFIG_STRING_THREAD_STRUCT,NULL,0};
config_getlist(config_get_if(), &THREADParamList, NULL, 0, NULL); config_getlist(config_get_if(), &THREADParamList, NULL, 0, NULL);
char *default_parallel_conf = "PARALLEL_RU_L1_TRX_SPLIT";
char *default_worker_conf = "WORKER_ENABLE";
char *parallel_conf = default_parallel_conf;
char *worker_conf = default_worker_conf;
if(THREADParamList.numelt>0) { if(THREADParamList.numelt>0) {
config_getlist(config_get_if(), &THREADParamList, ThreadParams, sizeofArray(ThreadParams), NULL); config_getlist(config_get_if(), &THREADParamList, ThreadParams, sizeofArray(ThreadParams), NULL);
parallel_conf = strdup(*(THREADParamList.paramarray[0][THREAD_PARALLEL_IDX].strptr)); parallel_conf = *(THREADParamList.paramarray[0][THREAD_PARALLEL_IDX].strptr);
} else {
parallel_conf = strdup("PARALLEL_RU_L1_TRX_SPLIT");
} }
if(THREADParamList.numelt>0) { if(THREADParamList.numelt>0) {
config_getlist(config_get_if(), &THREADParamList, ThreadParams, sizeofArray(ThreadParams), NULL); config_getlist(config_get_if(), &THREADParamList, ThreadParams, sizeofArray(ThreadParams), NULL);
worker_conf = strdup(*(THREADParamList.paramarray[0][THREAD_WORKER_IDX].strptr)); worker_conf = *(THREADParamList.paramarray[0][THREAD_WORKER_IDX].strptr);
} else {
worker_conf = strdup("WORKER_ENABLE");
} }
if(parallel_config == NULL) set_parallel_conf(parallel_conf); if(parallel_config == NULL) set_parallel_conf(parallel_conf);
if(worker_config == NULL) set_worker_conf(worker_conf); if(worker_config == NULL) set_worker_conf(worker_conf);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment