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

@ -1706,15 +1706,15 @@ xml_find_body_obj(cxobj *xt,
int
xml_free(cxobj *x)
{
int i;
int i;
cxobj *xc;
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);
@ -2032,12 +2032,12 @@ _xml_parse(const char *str,
cxobj *xt,
cxobj **xerr)
{
int retval = -1;
int retval = -1;
clixon_xml_yacc ya = {0,};
cxobj *x;
int ret;
int failed = 0; /* yang assignment */
int i;
cxobj *x;
int ret;
int failed = 0; /* yang assignment */
int i;
clicon_debug(1, "%s %s", __FUNCTION__, str);
if (strlen(str) == 0)

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

@ -178,8 +178,8 @@ xml_parse_version(clixon_xml_yacc *ya,
*/
static int
xml_parse_prefixed_name(clixon_xml_yacc *ya,
char *prefix,
char *name)
char *prefix,
char *name)
{
int retval = -1;
cxobj *x;
@ -201,7 +201,8 @@ xml_parse_prefixed_name(clixon_xml_yacc *ya,
done:
if (prefix)
free(prefix);
free(name);
if (name)
free(name);
return retval;
}
@ -242,8 +243,8 @@ xml_parse_endslash_post(clixon_xml_yacc *ya)
*/
static int
xml_parse_bslash(clixon_xml_yacc *ya,
char *prefix,
char *name)
char *prefix,
char *name)
{
int retval = -1;
cxobj *x = ya->ya_xelement;
@ -279,7 +280,10 @@ xml_parse_bslash(clixon_xml_yacc *ya,
}
retval = 0;
done:
free(name);
if (prefix)
free(prefix);
if (name)
free(name);
return retval;
}
@ -412,7 +416,7 @@ comment : BCOMMENT ECOMMENT
pi : BQMARK NAME EQMARK {clicon_debug(2, "pi -> <? NAME ?>"); free($2); }
| BQMARK NAME STRING EQMARK
{clicon_debug(2, "pi -> <? NAME STRING ?>"); free($2); free($3);}
{ clicon_debug(2, "pi -> <? NAME STRING ?>"); free($2); free($3);}
;