Yang access function. Mem leak in USE_XML_INSERT

This commit is contained in:
Olof hagsand 2019-04-25 13:46:23 +02:00
parent 16de5f47ba
commit e4239496a8
7 changed files with 45 additions and 23 deletions

View file

@ -203,7 +203,7 @@ example_copy_extra(clicon_handle h, /* Clicon handle */
{
int retval = -1;
fprintf(stderr, "%s\n", __FUNCTION__);
// fprintf(stderr, "%s\n", __FUNCTION__);
retval = 0;
// done:
return retval;

View file

@ -138,18 +138,9 @@ typedef enum yang_class yang_class;
struct xml;
/* Yang data node
* See RFC7950 Sec 3:
* o data node: A node in the schema tree that can be instantiated in a
* data tree. One of container, leaf, leaf-list, list, anydata, and
* anyxml.
* XXX move to function
*/
#define yang_datanode(y) ((y)->ys_keyword == Y_CONTAINER || (y)->ys_keyword == Y_LEAF || (y)->ys_keyword == Y_LIST || (y)->ys_keyword == Y_LEAF_LIST || (y)->ys_keyword == Y_ANYXML || (y)->ys_keyword == Y_ANYDATA)
typedef struct yang_stmt yang_stmt; /* Defined in clixon_yang_internal */
typedef int (yang_applyfn_t)(yang_stmt *ys, void *arg);
/*
@ -197,6 +188,7 @@ int ys_populate(yang_stmt *ys, void *arg);
yang_stmt *yang_parse_file(int fd, const char *name, yang_stmt *ysp);
int yang_apply(yang_stmt *yn, enum rfc_6020 key, yang_applyfn_t fn,
void *arg);
int yang_datanode(yang_stmt *ys);
int yang_abs_schema_nodeid(yang_stmt *yspec, yang_stmt *ys,
char *schema_nodeid,
enum rfc_6020 keyword, yang_stmt **yres);

View file

@ -297,7 +297,9 @@ text_modify(clicon_handle h,
}
#ifdef USE_XML_INSERT
/* Add new xml node but without parent - insert when node fully
copied (see changed conditional below) */
* copied (see changed conditional below)
* Note x0 may dangle cases if exit before changed conditional
*/
if ((x0 = xml_new(x1name, NULL, (yang_stmt*)y0)) == NULL)
goto done;
#else
@ -400,6 +402,11 @@ text_modify(clicon_handle h,
#endif
retval = 1;
done:
#ifdef USE_XML_INSERT
/* Remove dangling added objects */
if (changed && x0 && xml_parent(x0)==NULL)
xml_purge(x0);
#endif
if (x0vec)
free(x0vec);
return retval;

View file

@ -934,9 +934,9 @@ xml_wrap(cxobj *xc,
* @retval 0 OK
* @retval -1
* @note you cannot remove xchild in the loop (unless yoy keep track of xprev)
*
* @note Linear complexity - use xml_child_rm if possible
* @see xml_free Free, dont remove from parent
* @see xml_child_rm Only remove dont free
* @see xml_child_rm Remove if child order is known (does not free)
* Differs from xml_free it is removed from parent.
*/
int

View file

@ -2867,6 +2867,26 @@ yang_apply(yang_stmt *yn,
return retval;
}
/*! Check if a node is a yang "data node"
* @param[in] ys Yang statement node
* @retval 0 Yang node is NOT a data node
* @retval !=0 Yang node IS a data noed
* @see RFC7950 Sec 3:
* o data node: A node in the schema tree that can be instantiated in a
* data tree. One of container, leaf, leaf-list, list, anydata, and
* anyxml.
*/
int
yang_datanode(yang_stmt *ys)
{
return (yang_keyword_get(ys) == Y_CONTAINER ||
yang_keyword_get(ys) == Y_LEAF ||
yang_keyword_get(ys) == Y_LIST ||
yang_keyword_get(ys) == Y_LEAF_LIST ||
yang_keyword_get(ys) == Y_ANYXML ||
yang_keyword_get(ys) == Y_ANYDATA);
}
/*! All the work for schema_nodeid functions both absolute and descendant
* Ignore prefixes, see _abs
* @param[in] yn Yang node. Find next yang stmt and return that if match.

View file

@ -5,7 +5,7 @@
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# Number of list/leaf-list entries in file
: ${perfnr:=20000}
: ${perfnr:=10000}
# Number of requests made get/put
: ${perfreq:=100}

View file

@ -169,16 +169,19 @@ testrun startup "$runvar" "$startvar" "$extravar" '<data><interfaces xmlns="urn:
# 2. Try different modes on Invalid running/startup/extra WITHOUT failsafe
# ensure all db:s are unchanged after failure.
new "Test invalid running in running mode"
testfail running "$invalidvar" "$startvar" "$extravar"
# Valgrind backend tests make no sense in backend crash tests
if [ $valgrindtest -ne 2 ]; then
new "Test invalid running in running mode"
testfail running "$invalidvar" "$startvar" "$extravar"
new "Run invalid startup in startup mode"
testfail startup "$runvar" "$invalidvar" "$extravar"
new "Run invalid startup in startup mode"
testfail startup "$runvar" "$invalidvar" "$extravar"
new "Test broken running in running mode"
testfail running "$brokenvar" "$startvar" "$extravar"
new "Test broken running in running mode"
testfail running "$brokenvar" "$startvar" "$extravar"
new "Run broken startup in startup mode"
testfail startup "$runvar" "$brokenvar" "$extravar"
new "Run broken startup in startup mode"
testfail startup "$runvar" "$brokenvar" "$extravar"
fi
rm -rf $dir