diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index 2c64902d9..644799421 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -26,6 +26,7 @@ class ProxySQL_GlobalVariables { struct { bool gdbg; bool nostart; + bool use_proxysql_mem; pthread_mutex_t start_mutex; bool foreground; #ifdef DEBUG diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index d03b40525..7e3258086 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -35,6 +35,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { global.gdbg=false; global.nostart=false; global.foreground=false; + global.use_proxysql_mem=false; pthread_mutex_init(&global.start_mutex,NULL); #ifdef DEBUG global.gdb=0; @@ -65,6 +66,7 @@ opt.add( opt->add((const char *)"",0,0,0,(const char *)"Starts only the admin service",(const char *)"-n",(const char *)"--no-start"); opt->add((const char *)"",0,0,0,(const char *)"Run in foreground",(const char *)"-f",(const char *)"--foreground"); opt->add((const char *)"~/proxysql.cnf",0,1,0,(const char *)"Configuraton file",(const char *)"-c",(const char *)"--config"); + opt->add((const char *)"",0,1,0,(const char *)"Disable custom memory allocator",(const char *)"-m",(const char *)"--no-memory"); opt->add((const char *)"",0,1,0,(const char *)"Datadir",(const char *)"-D",(const char *)"--datadir"); opt->add((const char *)"",0,1,0,(const char *)"Configuration DB path",(const char *)"-a",(const char *)"--admin-pathdb"); opt->add((const char *)"",0,1,0,(const char *)"Administration Unix Socket",(const char *)"-S",(const char *)"--admin-socket"); @@ -116,6 +118,9 @@ void ProxySQL_GlobalVariables::process_opts_pre() { GloVars.__cmd_proxysql_datadir=strdup(datadir.c_str()); } + if (opt->isSet("-m")) { + global.use_proxysql_mem=true; + } #ifdef DEBUG init_debug_struct(); diff --git a/lib/proxysql_mem.cpp b/lib/proxysql_mem.cpp index 7e7e5901d..3ae2f5da0 100644 --- a/lib/proxysql_mem.cpp +++ b/lib/proxysql_mem.cpp @@ -39,34 +39,41 @@ static inline void __push_mem_block(l_sfc *sfc, void *m) { l_sfp * l_mem_init() { l_sfp *s=(l_sfp *)__x_malloc(sizeof(l_sfp)); - int i; - for (i=0; isfc[i].stack=NULL; - s->sfc[i].mem_blocks=NULL; - s->sfc[i].elem_size=L_SFC_MIN_ELEM_SIZE * (1 << i) ; - s->sfc[i].alloc_cnt=0; - s->sfc[i].free_cnt=0; - s->sfc[i].blocks_cnt=0; - s->sfc[i].__mem_l_free_count=0; - } + if (GloVars.global.use_proxysql_mem==true) { + int i; + for (i=0; isfc[i].stack=NULL; + s->sfc[i].mem_blocks=NULL; + s->sfc[i].elem_size=L_SFC_MIN_ELEM_SIZE * (1 << i) ; + s->sfc[i].alloc_cnt=0; + s->sfc[i].free_cnt=0; + s->sfc[i].blocks_cnt=0; + s->sfc[i].__mem_l_free_count=0; + } + } return s; } void l_mem_destroy(l_sfp *s) { size_t i,j; - for (i=0; isfc[i].blocks_cnt;j++) { - free(s->sfc[i].mem_blocks[j]); - } - if (s->sfc[i].mem_blocks) { - free(s->sfc[i].mem_blocks); - } - } + if (GloVars.global.use_proxysql_mem==true) { + for (i=0; isfc[i].blocks_cnt;j++) { + free(s->sfc[i].mem_blocks[j]); + } + if (s->sfc[i].mem_blocks) { + free(s->sfc[i].mem_blocks); + } + } + } free(s); } void * __l_alloc(l_sfp *sfp, size_t size) { + if (GloVars.global.use_proxysql_mem==false) { + return malloc(size); + } if (size>L_SFC_MAX_ELEM_SIZE) { return __x_malloc(size); } @@ -119,6 +126,10 @@ void * l_alloc0(size_t size) { void __l_free(l_sfp *sfp, size_t size, void *p) { + if (GloVars.global.use_proxysql_mem==false) { + free(p); + return; + } if (size>L_SFC_MAX_ELEM_SIZE) { free(p); return;