Fix mount memory leakage, Add YANG_FLAG_MOUNTPOINT

This commit is contained in:
Olof hagsand 2023-11-29 18:57:54 +01:00
parent 81b4fdb274
commit c46872c3fd
4 changed files with 19 additions and 13 deletions

View file

@ -83,6 +83,10 @@
* leaf z;
* }
*/
#define YANG_FLAG_MOUNTPOINT 0x100 /* Mark node as populated mount-point
* Set by yang_mount_set.
* Used by ys_free
*/
/*
* Types

View file

@ -60,7 +60,7 @@ int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec);
int xml_yang_mount_get(clicon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec);
int xml_yang_mount_set(clicon_handle h, cxobj *x, yang_stmt *yspec);
int yang_mount_get_yspec_any(yang_stmt *y, yang_stmt **yspec);
int xml_yang_mount_freeall(cvec *cvv);
int yang_mount_freeall(cvec *cvv);
int yang_schema_mount_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int yang_schema_mount_statistics(clicon_handle h, cxobj *xt, int modules, cbuf *cb);
int yang_schema_yanglib_parse_mount(clicon_handle h, cxobj *xt);

View file

@ -256,6 +256,7 @@ yang_argument_set(yang_stmt *ys,
/*! Get yang statement CLIgen variable
*
* See comment under ys_cv for how this is used
* @param[in] ys Yang statement node
*/
cg_var*
@ -283,6 +284,7 @@ yang_cv_set(yang_stmt *ys,
/*! Get yang statement CLIgen variable vector
*
* See comment under ys_cvec for how this is used
* @param[in] ys Yang statement node
* @note To add entries, use yang_cvec_add(), since this function may return NULL
*/
@ -656,14 +658,14 @@ ys_new(enum rfc_6020 keyw)
_stats_yang_nr++;
return ys;
}
/*! Free a single yang statement, dont remove children
/*! Free a single yang statement, dont remove children, called after children freed
*
* @param[in] ys Yang node to remove
* @param[in] self Free own node including child vector
* @retval 0 OK
* @retval -1 Error
* @see ys_free
* @see ys_free Also free children
*/
int
ys_free1(yang_stmt *ys,
@ -680,10 +682,8 @@ ys_free1(yang_stmt *ys,
/* Schema mount uses cvec in unknown to keep track of all yspecs
* Freed here once.
*/
if (yang_keyword_get(ys) == Y_UNKNOWN &&
strcmp(yang_argument_get(ys), "yangmnt:mount-point") == 0){
xml_yang_mount_freeall(ys->ys_cvec);
}
if (yang_flag_get(ys, YANG_FLAG_MOUNTPOINT))
yang_mount_freeall(ys->ys_cvec);
cvec_free(ys->ys_cvec);
ys->ys_cvec = NULL;
}

View file

@ -41,7 +41,7 @@
* The calls into this code are:
* 1. yang_schema_mount_point() Check that a yang nod eis mount-point
* 2. xml_yang_mount_get(): from xml_bind_yang and xmldb_put
* 3. xml_yang_mount_freeall(): from ys_free1 when deallocatin YANG trees
* 3. xml_yang_mount_freeall(): from ys_free1 when deallocating YANG trees
* 4. yang_schema_mount_statedata(): from get_common/get_statedata to retrieve system state
* 5. yang_schema_yanglib_parse_mount(): from xml_bind_yang to parse and mount
* 6. yang_schema_get_child(): from xmldb_put/text_modify when adding new XML nodes
@ -164,7 +164,8 @@ yang_mount_get(yang_stmt *y,
/*! Set yangspec mount-point on yang node containing extension
*
* Mount-points are stored in unknown yang cvec
* Mount-points are stored in yang cvec in container/list node taht is a mount-point
* as defined in yang_schema_mount_point()
* @param[in] y Yang container/list containing unknown node
* @param[in] xpath Key for yspec on y, in canonical form
* @param[in] yspec Yangspec for this mount-point (consumed)
@ -204,6 +205,7 @@ yang_mount_set(yang_stmt *y,
/* tag yspec with key/xpath */
yang_cv_set(yspec, cv2);
cv_void_set(cv, yspec);
yang_flag_set(y, YANG_FLAG_MOUNTPOINT); /* Cache value */
retval = 0;
done:
return retval;
@ -249,7 +251,7 @@ xml_yang_mount_get(clicon_handle h,
if (xml_nsctx_node(xt, &nsc0) < 0)
goto done;
yspec0 = clicon_dbspec_yang(h);
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc0, &reason)) < 0)
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc1, &reason)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -305,7 +307,7 @@ xml_yang_mount_set(clicon_handle h,
if (xml_nsctx_node(x, &nsc0) < 0)
goto done;
yspec0 = clicon_dbspec_yang(h);
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc0, &reason)) < 0)
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc1, &reason)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_YANG, 0, "%s", cbuf_get(reason));
@ -362,7 +364,7 @@ yang_mount_get_yspec_any(yang_stmt *y,
* @retval 0 OK
*/
int
xml_yang_mount_freeall(cvec *cvv)
yang_mount_freeall(cvec *cvv)
{
cg_var *cv = NULL;
yang_stmt *ys;