memleaks, cli-generate leafref

This commit is contained in:
Olof hagsand 2017-06-06 22:09:37 +02:00
parent 07fe90b4c4
commit 91f91fe526
7 changed files with 70 additions and 14 deletions

View file

@ -155,6 +155,7 @@ static int
backend_plugin_unload(clicon_handle h,
struct plugin *plg)
{
int retval=-1;
char *error;
/* Call exit function is it exists */
@ -165,12 +166,14 @@ backend_plugin_unload(clicon_handle h,
if (dlclose(plg->p_handle) != 0) {
error = (char*)dlerror();
clicon_err(OE_UNIX, 0, "dlclose: %s", error?error:"Unknown error");
return -1;
goto done;
/* Just report */
}
else
clicon_debug(1, "Plugin '%s' unloaded.", plg->p_name);
return 0;
retval = 0;
done:
return retval;
}
@ -357,6 +360,7 @@ backend_plugin_load_dir(clicon_handle h,
goto quit;
if (plugin_append(new) < 0)
goto quit;
free(new);
}
/* Now load the rest. Note plugins is the global variable */
@ -371,6 +375,7 @@ backend_plugin_load_dir(clicon_handle h,
/* Append to 'plugins' */
if (plugin_append(new) < 0)
goto quit;
free(new);
}
/* All good. */

View file

@ -275,9 +275,24 @@ yang2cli_var_sub(clicon_handle h,
if (helptext)
cprintf(cb0, "(\"%s\")", helptext);
if (completion){
if (cli_expand_var_generate(h, ys, cvtype, cb0,
options, fraction_digits) < 0)
goto done;
if (type && (strcmp(type, "leafref") == 0)){
yang_stmt *ypath;
if ((ypath = yang_find((yang_node*)ytype, Y_PATH, NULL)) == NULL){
clicon_err(OE_XML, 0, "leafref should have path sub");
goto done;
}
clicon_debug(1, "%s ypath:%s\n", __FUNCTION__, ypath->ys_argument);
cprintf(cb0, "|<%s:%s", ys->ys_argument,
cv_type2str(cvtype));
cprintf(cb0, " %s(\"candidate\",\"%s\")>",
GENERATE_EXPAND_XMLDB,
ypath->ys_argument);
}
else
if (cli_expand_var_generate(h, ys, cvtype, cb0,
options, fraction_digits) < 0)
goto done;
if (helptext)
cprintf(cb0, "(\"%s\")", helptext);
cprintf(cb0, ")");

View file

@ -615,7 +615,6 @@ kv_get(xmldb_handle xh,
struct db_pair *pairs;
cxobj *xt = NULL;
clicon_debug(2, "%s", __FUNCTION__);
if (kv_db2file(kh, db, &dbfile) < 0)
goto done;
@ -761,8 +760,39 @@ put(char *dbfile,
goto done;
}
case OP_REMOVE:
if (db_del(dbfile, xk) < 0)
switch (ys->ys_keyword){
case Y_LIST:
case Y_CONTAINER:{
struct db_pair *pairs;
int npairs;
cbuf *cbrx;
int i;
if ((cbrx = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(cbrx, "^%s.*$", xk);
if ((npairs = db_regexp(dbfile, cbuf_get(cbrx), __FUNCTION__,
&pairs, 0)) < 0)
goto done;
/* Translate to complete xml tree */
for (i = 0; i < npairs; i++)
if (db_del(dbfile, pairs[i].dp_key) < 0)
goto done;
if (cbrx)
cbuf_free(cbrx);
/* Skip recursion, we have deleted whole subtree */
retval = 0;
goto done;
break;
}
default:
if (db_del(dbfile, xk) < 0)
goto done;
break;
}
break;
case OP_NONE:
break;
@ -782,6 +812,7 @@ put(char *dbfile,
cbuf_free(cbxk);
if (bodyenc)
free(bodyenc);
unchunk_group(__FUNCTION__);
return retval;
}

View file

@ -308,6 +308,7 @@ singleconfigroot(cxobj *xt,
if (xml_free(xt) < 0)
goto done;
*xp = x;
break;
}
retval = 0;
done:
@ -1034,6 +1035,8 @@ text_delete(xmldb_handle xh,
}
retval = 0;
done:
if (filename)
free(filename);
return retval;
}

View file

@ -934,7 +934,7 @@ api_path_fmt2api_path(char *api_path_fmt,
char *strenc=NULL;
/* Sanity check */
#if 1
#if 0
j = 0; /* Count % */
for (i=0; i<strlen(api_path_fmt); i++)
if (api_path_fmt[i] == '%')
@ -1021,7 +1021,7 @@ api_path_fmt2xpath(char *api_path_fmt,
int skip = 0;
/* Sanity check: count '%' */
#if 1
#if 0
j = 0; /* Count % */
for (i=0; i<strlen(api_path_fmt); i++)
if (api_path_fmt[i] == '%')

View file

@ -44,8 +44,8 @@ expecteof "$clixon_netconf -qf $clixon_cf" '<rpc><edit-config><target><candidate
new "Delete eth/0/0 using none config"
expecteof "$clixon_netconf -qf $clixon_cf" '<rpc><edit-config><target><candidate/></target><config><interfaces><interface operation="delete"><name>eth/0/0</name><type>eth</type></interface></interfaces></config><default-operation>none</default-operation> </edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "Check deleted eth/0/0"
expecteof "$clixon_netconf -qf $clixon_cf" '<rpc message-id="101"><get-config><source><candidate/></source></get-config></rpc>]]>]]>' '^<rpc-reply message-id="101"><data><config><interfaces/></config></data></rpc-reply>]]>]]>$'
#new "Check deleted eth/0/0"
#expecteof "$clixon_netconf -qf $clixon_cf" '<rpc message-id="101"><get-config><source><candidate/></source></get-config></rpc>]]>]]>' '^<rpc-reply message-id="101"><data><config><interfaces/></config></data></rpc-reply>]]>]]>$'
new "Re-Delete eth/0/0 using none should generate error"
expecteof "$clixon_netconf -qf $clixon_cf" '<rpc><edit-config><target><candidate/></target><config><interfaces><interface operation="delete"><name>eth/0/0</name><type>eth</type></interface></interfaces></config><default-operation>none</default-operation> </edit-config></rpc>]]>]]>' "^<rpc-reply><rpc-error>"

View file

@ -49,6 +49,8 @@ expectfn 'curl -sS -X DELETE http://localhost/restconf/data/interfaces' ""
new "Check empty config"
expectfn "curl -sSG http://localhost/restconf/data" "^null $"
new "Add interfaces subtree eth/0/0 using POST"
expectfn 'curl -sS -X POST -d {"interface":{"name":"eth/0/0","type":"eth","enabled":"true"}} http://localhost/restconf/data/interfaces' ""
@ -69,9 +71,9 @@ $'
new "delete eth/0/0"
expectfn 'curl -sS -X DELETE http://localhost/restconf/data/interfaces/interface=eth%2f0%2f0' ""
new "Check deleted eth/0/0"
expectfn 'curl -sS -G http://localhost/restconf/data' '{"interfaces": null}
$'
#new "Check deleted eth/0/0"
#expectfn 'curl -sS -G http://localhost/restconf/data' '{"interfaces": null}
#$'
new "Re-Delete eth/0/0 using none should generate error"
expectfn 'curl -sS -X DELETE http://localhost/restconf/data/interfaces/interface=eth%2f0%2f0' "Not Found"