Fixed memory leak in new candidate_validate function

Added error returns for clixon-lib process rpc empty returns
This commit is contained in:
Olof hagsand 2021-06-23 10:50:47 +02:00
parent cb469a2bc7
commit ba45d6d2a1
3 changed files with 57 additions and 45 deletions

View file

@ -612,20 +612,27 @@ candidate_validate(clicon_handle h,
* use clicon_err. */ * use clicon_err. */
if (xret && clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0) if (xret && clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
goto done; goto done;
plugin_transaction_abort_all(h, td);
if (!cbuf_len(cbret) && if (!cbuf_len(cbret) &&
netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
goto done; goto done;
goto fail; goto fail;
} }
if (xmldb_get0_clear(h, td->td_src) < 0 || if (xmldb_get0_clear(h, td->td_src) < 0 ||
xmldb_get0_clear(h, td->td_target) < 0){ xmldb_get0_clear(h, td->td_target) < 0)
plugin_transaction_abort_all(h, td);
goto done; goto done;
}
plugin_transaction_end_all(h, td); plugin_transaction_end_all(h, td);
retval = 1; retval = 1;
done: done:
if (xret)
xml_free(xret);
if (td){
if (retval < 1)
plugin_transaction_abort_all(h, td);
xmldb_get0_free(h, &td->td_target);
xmldb_get0_free(h, &td->td_src);
transaction_free(td);
}
return retval; return retval;
fail: fail:
retval = 0; retval = 0;

View file

@ -270,11 +270,11 @@ restconf_pseudo_process_control(clicon_handle h)
* see restconf_pseudo_set_log which sets flag when process starts * see restconf_pseudo_set_log which sets flag when process starts
*/ */
argv[i++] = "-D"; argv[i++] = "-D";
argv[i++] = strdup("0"); argv[i++] = "0";
argv[i++] = "-l"; argv[i++] = "-l";
argv[i++] = strdup("s"); /* There is also log-destination in clixon-restconf.yang */ argv[i++] = "s"; /* There is also log-destination in clixon-restconf.yang */
argv[i++] = "-R"; argv[i++] = "-R";
argv[i++] = strdup(""); argv[i++] = "";
argv[i++] = NULL; argv[i++] = NULL;
assert(i==nr); assert(i==nr);
if (clixon_process_register(h, RESTCONF_PROCESS, if (clixon_process_register(h, RESTCONF_PROCESS,

View file

@ -682,9 +682,9 @@ clixon_process_status(clicon_handle h,
int run; int run;
int i; int i;
char timestr[28]; char timestr[28];
int match = 0;
if (_proc_entry_list == NULL) if (_proc_entry_list != NULL){
goto ok;
pe = _proc_entry_list; pe = _proc_entry_list;
do { do {
if (strcmp(pe->pe_name, name) == 0){ if (strcmp(pe->pe_name, name) == 0){
@ -719,11 +719,16 @@ clixon_process_status(clicon_handle h,
if (pe->pe_pid) if (pe->pe_pid)
cprintf(cbret, "<pid xmlns=\"%s\">%u</pid>", CLIXON_LIB_NS, pe->pe_pid); cprintf(cbret, "<pid xmlns=\"%s\">%u</pid>", CLIXON_LIB_NS, pe->pe_pid);
cprintf(cbret, "</rpc-reply>"); cprintf(cbret, "</rpc-reply>");
match++;
break; /* hit break here */ break; /* hit break here */
} }
pe = NEXTQ(process_entry_t *, pe); pe = NEXTQ(process_entry_t *, pe);
} while (pe != _proc_entry_list); } while (pe != _proc_entry_list);
ok: }
if (!match){ /* No match, return error */
if (netconf_unknown_element(cbret, "application", (char*)name, "Process service is not known") < 0)
goto done;
}
retval = 0; retval = 0;
done: done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);