memory leaks

This commit is contained in:
Olof hagsand 2020-02-21 10:23:42 +01:00
parent 51a28f9bbf
commit b31297cb21
5 changed files with 98 additions and 17 deletions

View file

@ -1711,10 +1711,10 @@ xml_free(cxobj *x)
if (x->x_name)
free(x->x_name);
if (x->x_value_cb)
cbuf_free(x->x_value_cb);
if (x->x_prefix)
free(x->x_prefix);
if (x->x_value_cb)
cbuf_free(x->x_value_cb);
for (i=0; i<x->x_childvec_len; i++){
if ((xc = x->x_childvec[i]) != NULL){
xml_free(xc);

View file

@ -601,6 +601,82 @@ xml_diff(yang_stmt *yspec,
* @note This function seems a little too complex semantics
* @see xml_tree_prune_flagged for a simpler variant
*/
#if 1
int
xml_tree_prune_flagged_sub(cxobj *xt,
int flag,
int test,
int *upmark)
{
int retval = -1;
int submark;
int mark;
cxobj *x;
cxobj *xprev;
int iskey;
int anykey=0;
yang_stmt *yt;
mark = 0;
yt = xml_spec(xt); /* xan be null */
x = NULL;
xprev = x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if (xml_flag(x, flag) == test?flag:0){
/* Pass test */
mark++;
xprev = x;
continue; /* mark and stop here */
}
/* If it is key dont remove it yet (see second round) */
if (yt){
if ((iskey = yang_key_match(yt, xml_name(x))) < 0)
goto done;
if (iskey){
anykey++;
xprev = x; /* skip if this is key */
continue;
}
}
if (xml_tree_prune_flagged_sub(x, flag, test, &submark) < 0)
goto done;
/* if xt is list and submark anywhere, then key subs are also marked
*/
if (submark)
mark++;
else{ /* Safe with xml_child_each if last */
if (xml_purge(x) < 0)
goto done;
x = xprev;
}
xprev = x;
}
/* Second round: if any keys were found, and no marks detected, purge now */
if (anykey && !mark){
x = NULL;
xprev = x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
/* If it is key remove it here */
if (yt){
if ((iskey = yang_key_match(yt, xml_name(x))) < 0)
goto done;
if (iskey && xml_purge(x) < 0)
goto done;
x = xprev;
}
xprev = x;
}
}
retval = 0;
done:
if (upmark)
*upmark = mark;
return retval;
}
#else
/* This is optimized in the sense that xml_purge is replaced with xml_child_rm but it leaks memory,
* in poarticualr attributes and namespace caches
*/
int
xml_tree_prune_flagged_sub(cxobj *xt,
int flag,
@ -687,7 +763,7 @@ xml_tree_prune_flagged_sub(cxobj *xt,
*upmark = mark;
return retval;
}
#endif
/*! Prune everything that passes test
* @param[in] xt XML tree with some node marked
* @param[in] flag Which flag to test for

View file

@ -201,6 +201,7 @@ xml_parse_prefixed_name(clixon_xml_yacc *ya,
done:
if (prefix)
free(prefix);
if (name)
free(name);
return retval;
}
@ -279,6 +280,9 @@ xml_parse_bslash(clixon_xml_yacc *ya,
}
retval = 0;
done:
if (prefix)
free(prefix);
if (name)
free(name);
return retval;
}

View file

@ -31,7 +31,7 @@ memonce(){
perfnr=100 # test_perf.sh restconf put more or less stops
perfreq=10
clixon_backend="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=yes --log-file=$valgrindfile clixon_backend"
clixon_backend="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=yes --log-file=$valgrindfile clixon_backend"
;;
'restconf')
valgrindtest=3 # This means backend valgrind test

View file

@ -10,6 +10,7 @@
# with different paths.
# Using the -sS <file> state capability of the main example, that is why CLICON_BACKEND_DIR is
# /usr/local/lib/$APPNAME/backend so that the main backend plugins is included.
# These tests require VALIDATE_STATE_XML to be set
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi