From a1fe08011138e01e515d479d77bd279de75d0cb8 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 5 Nov 2021 14:43:28 +0100 Subject: [PATCH] CLIgen mem leak, test augment --- apps/cli/cli_plugin.c | 4 +++- test/test_augment.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 90b7ec5b..f83a99e6 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -651,7 +651,7 @@ clicon_parse(clicon_handle h, cli_syntax_t *stx = NULL; cli_syntaxmode_t *csm; parse_tree *pt; /* Orig */ - cg_obj *match_obj; + cg_obj *match_obj = NULL; cvec *cvv = NULL; FILE *f; char *reason = NULL; @@ -731,6 +731,8 @@ done: free(reason); if (cvv) cvec_free(cvv); + if (match_obj) + co_free(match_obj, 0); return retval; } diff --git a/test/test_augment.sh b/test/test_augment.sh index a25eaede..65dfaf0d 100755 --- a/test/test_augment.sh +++ b/test/test_augment.sh @@ -185,6 +185,18 @@ module example-augment { type string; } } + /* augment a list */ + augment "/if:interfaces" { + list ports{ + key id; + leaf id { + type int32; + } + leaf str { + type string; + } + } + } } EOF @@ -291,6 +303,30 @@ expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-inte new "restconf GET augment multi-namespace cross level 2" expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces/interface=e1/example-augment:ospf/reference-bandwidth)" 0 "HTTP/$HVER 200" '{"example-augment:reference-bandwidth":23}' +new "delete interfaces" +expectpart "$(curl $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces)" 0 "HTTP/$HVER 204" + +# augmented lists +XML="22nisse44kalle" +new "netconf PUT augmented list" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOmerge$XML]]>]]>" "^]]>]]>$" + +new "netconf commit" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" + +new "netconf get config" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "$XML]]>]]>" + +JSON='{"ietf-interfaces:interfaces":{"example-augment:ports":[{"id":22,"str":"foo"},{"id":44,"str":"bar"}]}}' + +new "restconf PUT augmented list" +expectpart "$(curl $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces -d "$JSON")" 0 "HTTP/$HVER 204" + +# Escaped [] why? +JSON1='{"ietf-interfaces:interfaces":{"example-augment:ports":\[{"id":22,"str":"foo"},{"id":44,"str":"bar"}\]}}' +new "restconf GET augmented list" +expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces)" 0 "HTTP/$HVER 200" "$JSON1" + if [ $RC -ne 0 ]; then new "Kill restconf daemon" stop_restconf