Fixed memory issue as result of optimization, modify xmldb_copy to reset rather than free
This commit is contained in:
parent
fa62eb0872
commit
b7d91607b6
3 changed files with 29 additions and 9 deletions
|
|
@ -242,7 +242,7 @@ char *xml_value(cxobj *xn);
|
|||
int xml_value_set(cxobj *xn, char *val);
|
||||
int xml_value_append(cxobj *xn, char *val);
|
||||
enum cxobj_type xml_type(cxobj *xn);
|
||||
|
||||
enum cxobj_type xml_type_set(cxobj *xn, enum cxobj_type type);
|
||||
int xml_child_nr(cxobj *xn);
|
||||
int xml_child_nr_type(cxobj *xn, enum cxobj_type type);
|
||||
int xml_child_nr_notype(cxobj *xn, enum cxobj_type type);
|
||||
|
|
@ -285,6 +285,7 @@ cxobj *xml_find_type(cxobj *xn_parent, const char *prefix, const char *name,
|
|||
char *xml_find_value(cxobj *xn_parent, const char *name);
|
||||
char *xml_find_body(cxobj *xn, const char *name);
|
||||
cxobj *xml_find_body_obj(cxobj *xt, const char *name, char *val);
|
||||
int xml_free0(cxobj *x);
|
||||
int xml_free(cxobj *xn);
|
||||
int xml_copy_one(cxobj *xn0, cxobj *xn1);
|
||||
int xml_copy(cxobj *x0, cxobj *x1);
|
||||
|
|
|
|||
|
|
@ -328,8 +328,9 @@ xmldb_copy(clixon_handle h,
|
|||
goto done;
|
||||
}
|
||||
else{ /* copy x1 to x2 */
|
||||
xml_free(x2);
|
||||
if ((x2 = xml_new(xml_name(x1), NULL, CX_ELMNT)) == NULL)
|
||||
xml_free0(x2);
|
||||
xml_type_set(x2, CX_ELMNT);
|
||||
if (xml_name_set(x2, xml_name(x1)) < 0)
|
||||
goto done;
|
||||
xml_flag_set(x2, XML_FLAG_TOP);
|
||||
if (xml_copy(x1, x2) < 0)
|
||||
|
|
|
|||
|
|
@ -743,7 +743,7 @@ xml_type(cxobj *xn)
|
|||
* @param[in] type new type
|
||||
* @retval type old type
|
||||
*/
|
||||
static enum cxobj_type
|
||||
enum cxobj_type
|
||||
xml_type_set(cxobj *xn,
|
||||
enum cxobj_type type)
|
||||
{
|
||||
|
|
@ -1945,26 +1945,28 @@ xml_find_body_obj(cxobj *xt,
|
|||
return x;
|
||||
}
|
||||
|
||||
/*! Free an xl sub-tree recursively, but do not remove it from parent
|
||||
/*! Free an xml sub-tree recursively, reset it, but not object itself, do not remove it from parent
|
||||
*
|
||||
* @param[in] x the xml tree to be freed.
|
||||
* @param[in] x the xml tree to be reset
|
||||
* @see xml_purge where x is also removed from parent
|
||||
* @see xml_free also free object
|
||||
*/
|
||||
int
|
||||
xml_free(cxobj *x)
|
||||
xml_free0(cxobj *x)
|
||||
{
|
||||
int i;
|
||||
cxobj *xc;
|
||||
size_t sz;
|
||||
|
||||
if (x == NULL){
|
||||
if (x == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (x->x_name)
|
||||
free(x->x_name);
|
||||
if (x->x_prefix)
|
||||
free(x->x_prefix);
|
||||
switch (xml_type(x)){
|
||||
case CX_ELMNT:
|
||||
sz = sizeof(struct xml);
|
||||
for (i=0; i<x->x_childvec_len; i++){
|
||||
if ((xc = x->x_childvec[i]) != NULL){
|
||||
xml_free(xc);
|
||||
|
|
@ -1983,12 +1985,28 @@ xml_free(cxobj *x)
|
|||
break;
|
||||
case CX_BODY:
|
||||
case CX_ATTR:
|
||||
sz = sizeof(struct xmlbody);
|
||||
if (x->x_value_cb)
|
||||
cbuf_free(x->x_value_cb);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
memset(x, 0, sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Free an xml sub-tree recursively, but do not remove it from parent
|
||||
*
|
||||
* @param[in] x the xml tree to be freed.
|
||||
* @see xml_purge where x is also removed from parent
|
||||
*/
|
||||
int
|
||||
xml_free(cxobj *x)
|
||||
{
|
||||
if (x == NULL)
|
||||
return 0;
|
||||
xml_free0(x);
|
||||
free(x);
|
||||
_stats_xml_nr--;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue