Restconf mem leak

This commit is contained in:
Olof hagsand 2024-10-22 12:44:49 +02:00
parent 315e554637
commit fa93364953
6 changed files with 26 additions and 17 deletions

View file

@ -128,6 +128,8 @@ restconf_not_acceptable(clixon_handle h,
goto done; goto done;
retval = 0; retval = 0;
done: done:
if (xerr)
xml_free(xerr);
return retval; return retval;
} }

View file

@ -1202,20 +1202,24 @@ netconf_operation_not_supported_xml(cxobj **xret,
int retval =-1; int retval =-1;
cxobj *xerr; cxobj *xerr;
char *encstr = NULL; char *encstr = NULL;
cxobj *x = NULL;
if (xret == NULL){ if (xret == NULL){
clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
goto done; goto done;
} }
if (*xret == NULL){ if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL) if ((x = xml_new("rpc-reply", NULL, CX_ELMNT)) == NULL)
goto done; goto done;
} }
else if (xml_name_set(*xret, "rpc-reply") < 0) else {
x = *xret;
if (xml_name_set(x, "rpc-reply") < 0)
goto done; goto done;
if (xml_add_attr(*xret, "xmlns", NETCONF_BASE_NAMESPACE, NULL, NULL) == NULL) }
if (xml_add_attr(x, "xmlns", NETCONF_BASE_NAMESPACE, NULL, NULL) == NULL)
goto done; goto done;
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL) if ((xerr = xml_new("rpc-error", x, CX_ELMNT)) == NULL)
goto done; goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "<error-type>%s</error-type>" if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>operation-not-supported</error-tag>" "<error-tag>operation-not-supported</error-tag>"
@ -1229,8 +1233,13 @@ netconf_operation_not_supported_xml(cxobj **xret,
encstr) < 0) encstr) < 0)
goto done; goto done;
} }
if (x != *xret)
*xret = x;
x = NULL;
retval = 0; retval = 0;
done: done:
if (x && x != *xret)
xml_free(x);
if (encstr) if (encstr)
free(encstr); free(encstr);
return retval; return retval;

View file

@ -1533,7 +1533,6 @@ upgrade_callback_call(clixon_handle h,
{ {
int retval = -1; int retval = -1;
upgrade_callback_t *uc; upgrade_callback_t *uc;
int nr = 0; /* How many callbacks */
int ret; int ret;
plugin_module_struct *ms = plugin_module_struct_get(h); plugin_module_struct *ms = plugin_module_struct_get(h);
@ -1564,7 +1563,6 @@ upgrade_callback_call(clixon_handle h,
} }
goto fail; goto fail;
} }
nr++;
} }
uc = NEXTQ(upgrade_callback_t *, uc); uc = NEXTQ(upgrade_callback_t *, uc);
} while (uc != ms->ms_upgrade_callbacks); } while (uc != ms->ms_upgrade_callbacks);

View file

@ -912,7 +912,6 @@ xml_yang_validate_unique(cxobj *xt,
yang_stmt *y; yang_stmt *y;
yang_stmt *yprev = NULL; yang_stmt *yprev = NULL;
enum rfc_6020 keyw; enum rfc_6020 keyw;
int nr = 0;
int ret; int ret;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){ while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){
@ -922,10 +921,8 @@ xml_yang_validate_unique(cxobj *xt,
if (keyw == Y_LIST || keyw == Y_LEAF_LIST){ if (keyw == Y_LIST || keyw == Y_LEAF_LIST){
/* equal: just continue*/ /* equal: just continue*/
if (y == yprev){ if (y == yprev){
nr++;
continue; continue;
} }
nr=1;
/* new list check */ /* new list check */
switch (keyw){ switch (keyw){
case Y_LIST: case Y_LIST:

View file

@ -596,6 +596,7 @@ function start_restconf(){
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
err1 "expected 0" "$?" err1 "expected 0" "$?"
fi fi
RCPID=$!
} }
# Stop restconf daemon before test # Stop restconf daemon before test
@ -609,10 +610,12 @@ function stop_restconf_pre(){
# 2) Dont use -u $WWWUSER since clixon_restconf may drop privileges. # 2) Dont use -u $WWWUSER since clixon_restconf may drop privileges.
# 3) After fork, it seems to take some time before name is right # 3) After fork, it seems to take some time before name is right
function stop_restconf(){ function stop_restconf(){
sudo pkill -f clixon_restconf
if [ $valgrindtest -eq 3 ]; then if [ $valgrindtest -eq 3 ]; then
sudo kill ${RCPID}
sleep 1 sleep 1
checkvalgrind checkvalgrind
else
sudo pkill -f clixon_restconf
fi fi
} }

View file

@ -13,7 +13,6 @@ function memonce(){
valgrindfile=$(mktemp) valgrindfile=$(mktemp)
echo "valgrindfile:$valgrindfile" echo "valgrindfile:$valgrindfile"
clixon_backend= clixon_backend=
clixon_restconf= clixon_restconf=
clixon_cli= clixon_cli=
@ -30,9 +29,10 @@ function memonce(){
;; ;;
'restconf') 'restconf')
valgrindtest=3 # This means restconf valgrind test valgrindtest=3 # This means restconf valgrind test
sudo chown root $valgrindfile
sudo chmod 777 $valgrindfile
: ${DEMWAIT:=15} # valgrind backend needs some time to get up : ${DEMWAIT:=15} # valgrind backend needs some time to get up
clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf" clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf"
;; ;;
'cli') 'cli')
valgrindtest=1 valgrindtest=1