From 42a974bf78f62a6326a140de8aac4c396b3188e8 Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Wed, 5 Jun 2019 09:54:13 +0000 Subject: [PATCH] mem problem in refine/augment code --- lib/src/clixon_yang.c | 21 ++++++++++++--------- test/mem.sh | 5 ++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 8ecf3017..726d0963 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2183,10 +2183,14 @@ yang_expand_grouping(yang_stmt *yn) goto done; ygrouping->ys_flags |= YANG_FLAG_MARK; /* Mark as expanded */ } + /* Make a copy of the grouping, then make refinements to this copy + */ + if ((ygrouping2 = ys_dup(ygrouping)) == NULL) + goto done; /* Replace ys with ygrouping,... * First enlarge parent vector */ - glen = ygrouping->ys_len; + glen = ygrouping2->ys_len; /* * yn is parent: the children of ygrouping replaces ys. * Is there a case when glen == 0? YES AND THIS BREAKS @@ -2196,7 +2200,7 @@ yang_expand_grouping(yang_stmt *yn) yn->ys_len += glen - 1; if (glen && (yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){ clicon_err(OE_YANG, errno, "realloc"); - return -1; + goto done; } /* Then move all existing elements up from i+1 (not uses-stmt) */ if (size) @@ -2205,11 +2209,7 @@ yang_expand_grouping(yang_stmt *yn) size); } - /* Make a copy of the while grouping making it easier to - * refine it */ - if ((ygrouping2 = ys_dup(ygrouping)) == NULL) - goto done; - /* Iterate through refinments and modify grouping copy + /* Iterate through refinements and modify grouping copy * See RFC 7950 7.13.2 yrt is the refine target node */ yr = NULL; @@ -2241,6 +2241,9 @@ yang_expand_grouping(yang_stmt *yn) } /* Remove 'uses' node */ ys_free(ys); + /* Remove the grouping copy */ + ygrouping2->ys_len = 0; + ys_free(ygrouping2); break; /* Note same child is re-iterated since it may be changed */ default: i++; @@ -2600,8 +2603,8 @@ ys_schemanode_check(yang_stmt *ys, if (yang_desc_schema_nodeid(yp, ys->ys_argument, -1, &yres) < 0) goto done; if (yres == NULL){ - clicon_err(OE_YANG, 0, "schemanode sanity check of %d %s", - ys->ys_keyword, + clicon_err(OE_YANG, 0, "schemanode sanity check of %s %s", + yang_key2str(ys->ys_keyword), ys->ys_argument); goto done; } diff --git a/test/mem.sh b/test/mem.sh index a35193d3..02072ecd 100755 --- a/test/mem.sh +++ b/test/mem.sh @@ -2,6 +2,9 @@ # Run valgrind leak test for cli, restconf, netconf or background. # Stop on first error +# Pattern to run tests +: ${pattern:=test_*.sh} + # Run valgrindtest once, args: # what: (cli|netconf|restconf|backend)* # no args means all memonce(){ @@ -45,7 +48,7 @@ memonce(){ esac err=0 - for test in test_*.sh; do + for test in $pattern; do if [ $testnr != 0 ]; then echo; fi testfile=$test . ./$test