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;
retval = 0;
done:
if (xerr)
xml_free(xerr);
return retval;
}

View file

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

View file

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

View file

@ -912,7 +912,6 @@ xml_yang_validate_unique(cxobj *xt,
yang_stmt *y;
yang_stmt *yprev = NULL;
enum rfc_6020 keyw;
int nr = 0;
int ret;
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){
/* equal: just continue*/
if (y == yprev){
nr++;
continue;
}
nr=1;
/* new list check */
switch (keyw){
case Y_LIST:

View file

@ -596,6 +596,7 @@ function start_restconf(){
if [ $? -ne 0 ]; then
err1 "expected 0" "$?"
fi
RCPID=$!
}
# Stop restconf daemon before test
@ -609,10 +610,12 @@ function stop_restconf_pre(){
# 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
if [ $valgrindtest -eq 3 ]; then
sudo kill ${RCPID}
sleep 1
checkvalgrind
else
sudo pkill -f clixon_restconf
fi
}

View file

@ -13,7 +13,6 @@ function memonce(){
valgrindfile=$(mktemp)
echo "valgrindfile:$valgrindfile"
clixon_backend=
clixon_restconf=
clixon_cli=
@ -30,9 +29,10 @@ function memonce(){
;;
'restconf')
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
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')
valgrindtest=1