From 3539a80d5e92b7ea189ed6c63a2bdef5bf5f2c2a Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 27 Jun 2021 16:32:10 +0200 Subject: [PATCH] restconf fcgi mem leak in indata test pkill needs sleep before name settles --- apps/restconf/restconf_api_fcgi.c | 5 ++++- apps/restconf/restconf_api_native.c | 6 +++--- apps/restconf/restconf_root.c | 4 ++++ lib/src/clixon_proc.c | 3 ++- test/lib.sh | 3 ++- test/test_restconf_internal.sh | 8 ++++---- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/restconf/restconf_api_fcgi.c b/apps/restconf/restconf_api_fcgi.c index 2eb788f3..7d1c58cd 100644 --- a/apps/restconf/restconf_api_fcgi.c +++ b/apps/restconf/restconf_api_fcgi.c @@ -220,8 +220,11 @@ restconf_reply_send(void *req0, return retval; } -/*! +/*! Get input data from http request, eg such as curl -X PUT http://... * @param[in] req Fastcgi request handle + * @retval indata + * @retval NULL Error + * @note: creates a new cbuf which differs from native api where a pointer is returned */ cbuf * restconf_get_indata(void *req0) diff --git a/apps/restconf/restconf_api_native.c b/apps/restconf/restconf_api_native.c index cf5df644..c4162b2e 100644 --- a/apps/restconf/restconf_api_native.c +++ b/apps/restconf/restconf_api_native.c @@ -172,9 +172,9 @@ restconf_reply_send(void *req0, return retval; } -/*! get input data - * @param[in] req Fastcgi request handle - * @note Pulls up an event buffer and then copies it to a cbuf. This is not efficient. +/*! Get input data from http request, eg such as curl -X PUT http://... + * @param[in] req Request handle + * @note: reuses cbuf from stream-data */ cbuf * restconf_get_indata(void *req0) diff --git a/apps/restconf/restconf_root.c b/apps/restconf/restconf_root.c index 5161f8e8..aa79953e 100644 --- a/apps/restconf/restconf_root.c +++ b/apps/restconf/restconf_root.c @@ -588,6 +588,10 @@ api_root_restconf(clicon_handle h, retval = 0; done: clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); +#ifdef WITH_RESTCONF_FCGI + if (cb) + cbuf_free(cb); +#endif if (xerr) xml_free(xerr); if (username) diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index b96fc877..8c51b6e1 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -648,7 +648,7 @@ clixon_process_operation(clicon_handle h, sched++;/* start: immediate stop/restart: not immediate: wait timeout */ } else{ - clicon_debug(1, "%s name:%s op %s cancelled by wrwap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); + clicon_debug(1, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); } break; /* hit break here */ } @@ -688,6 +688,7 @@ clixon_process_status(clicon_handle h, pe = _proc_entry_list; do { if (strcmp(pe->pe_name, name) == 0){ + clicon_debug(1, "%s found %s pid:%d", __FUNCTION__, name, pe->pe_pid); /* Check if running */ run = 0; if (pe->pe_pid && proc_op_run(pe->pe_pid, &run) < 0) diff --git a/test/lib.sh b/test/lib.sh index 67b7e82c..faee3d50 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -382,9 +382,10 @@ function stop_restconf_pre(){ } # Stop restconf daemon after test -# Two caveats in pkill: +# Some problems with pkill: # 1) Dont use $clixon_restconf (dont work in valgrind) # 2) Dont use -u $WWWUSER since clixon_restconf may drop privileges. +# 3) After fork, it seems to take some time before name is right function stop_restconf(){ sudo pkill -f clixon_restconf if [ $valgrindtest -eq 3 ]; then diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh index 44cc31ab..905c4162 100755 --- a/test/test_restconf_internal.sh +++ b/test/test_restconf_internal.sh @@ -167,6 +167,7 @@ cat< $startupdb EOF new "kill old restconf" +sleep $DEMSLEEP stop_restconf_pre new "test params: -f $cfg" @@ -276,9 +277,8 @@ if [ $pid0 -eq $pid3 ]; then fi new "kill restconf using kill" -stop_restconf_pre - sleep $DEMSLEEP +stop_restconf_pre new "Wait for restconf to stop" wait_restconf_stopped @@ -378,6 +378,7 @@ cat< $startupdb EOF new "kill old restconf" +sleep $DEMSLEEP stop_restconf_pre new "test params: -f $cfg" @@ -485,10 +486,9 @@ fi #Start backend -s none should start new "kill restconf" +sleep $DEMSLEEP stop_restconf -sleep $DEMSLEEP # Lots of processes need to die before next test - new "endtest" endtest