Fixes after coverity static analysis
This commit is contained in:
parent
d94b4f5b7c
commit
a1badc312e
24 changed files with 148 additions and 70 deletions
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
|
@ -50,7 +50,7 @@ jobs:
|
||||||
- name: install example
|
- name: install example
|
||||||
run: (cd example; sudo make install)
|
run: (cd example; sudo make install)
|
||||||
|
|
||||||
docker-alpine-tests-a-j:
|
docker-alpine-tests-a-l:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
|
|
@ -79,9 +79,9 @@ jobs:
|
||||||
- name: start container
|
- name: start container
|
||||||
run: ./start.sh
|
run: ./start.sh
|
||||||
- name: run test
|
- name: run test
|
||||||
run: sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true pattern=test_a*.sh pattern=test_c*.sh pattern=test_d*.sh pattern=test_f*.sh pattern=test_h*.sh pattern=test_i*.sh pattern=test_j*.sh ./sum.sh'
|
run: sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true pattern=test_a*.sh pattern=test_c*.sh pattern=test_d*.sh pattern=test_f*.sh pattern=test_h*.sh pattern=test_i*.sh pattern=test_j*.sh pattern=test_l*.sh pattern=test_m*.sh ./sum.sh'
|
||||||
|
|
||||||
docker-alpine-tests-l-r:
|
docker-alpine-tests-n-p:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
|
|
@ -110,7 +110,7 @@ jobs:
|
||||||
- name: start container
|
- name: start container
|
||||||
run: ./start.sh
|
run: ./start.sh
|
||||||
- name: run test
|
- name: run test
|
||||||
run: sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true pattern=test_l*.sh pattern=test_m*.sh pattern=test_n*.sh pattern=test_o*.sh pattern=test_p*.sh ./sum.sh'
|
run: sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true pattern=test_n*.sh pattern=test_o*.sh pattern=test_p*.sh ./sum.sh'
|
||||||
|
|
||||||
docker-alpine-tests-r-z:
|
docker-alpine-tests-r-z:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -307,10 +307,14 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
|
||||||
if (clixon_resource_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
|
if (clixon_resource_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (xp && x)
|
if (xp && x){
|
||||||
*xp = x;
|
*xp = x;
|
||||||
|
x = NULL;
|
||||||
|
}
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
|
if (x)
|
||||||
|
xml_free(x);
|
||||||
return retval;
|
return retval;
|
||||||
fail:
|
fail:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ backend_accept_client(int fd,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
clixon_handle h = (clixon_handle)arg;
|
clixon_handle h = (clixon_handle)arg;
|
||||||
int s;
|
int s = -1;
|
||||||
struct sockaddr from = {0,};
|
struct sockaddr from = {0,};
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
struct client_entry *ce;
|
struct client_entry *ce;
|
||||||
|
|
@ -297,8 +297,11 @@ backend_accept_client(int fd,
|
||||||
*/
|
*/
|
||||||
if (clixon_event_reg_fd(s, from_client, (void*)ce, "local netconf client socket") < 0)
|
if (clixon_event_reg_fd(s, from_client, (void*)ce, "local netconf client socket") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
s = -1;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (s != -1)
|
||||||
|
close(s);
|
||||||
if (name)
|
if (name)
|
||||||
free(name);
|
free(name);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ backend_client_add(clixon_handle h,
|
||||||
struct sockaddr *addr)
|
struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
struct backend_handle *bh = handle(h);
|
struct backend_handle *bh = handle(h);
|
||||||
struct client_entry *ce;
|
struct client_entry *ce = NULL;
|
||||||
|
|
||||||
if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){
|
if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){
|
||||||
clixon_err(OE_PLUGIN, errno, "malloc");
|
clixon_err(OE_PLUGIN, errno, "malloc");
|
||||||
|
|
@ -151,15 +151,16 @@ backend_client_add(clixon_handle h,
|
||||||
memset(ce, 0, sizeof(*ce));
|
memset(ce, 0, sizeof(*ce));
|
||||||
ce->ce_nr = bh->bh_ce_nr++; /* Session-id ? */
|
ce->ce_nr = bh->bh_ce_nr++; /* Session-id ? */
|
||||||
memcpy(&ce->ce_addr, addr, sizeof(*addr));
|
memcpy(&ce->ce_addr, addr, sizeof(*addr));
|
||||||
ce->ce_next = bh->bh_ce_list;
|
|
||||||
ce->ce_handle = h;
|
ce->ce_handle = h;
|
||||||
if (clicon_session_id_get(h, &ce->ce_id) < 0){
|
if (clicon_session_id_get(h, &ce->ce_id) < 0){
|
||||||
clixon_err(OE_NETCONF, ENOENT, "session_id not set");
|
clixon_err(OE_NETCONF, ENOENT, "session_id not set");
|
||||||
|
free(ce);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
clicon_session_id_set(h, ce->ce_id + 1);
|
clicon_session_id_set(h, ce->ce_id + 1);
|
||||||
gettimeofday(&ce->ce_time, NULL);
|
gettimeofday(&ce->ce_time, NULL);
|
||||||
netconf_monitoring_counter_inc(h, "in-sessions");
|
netconf_monitoring_counter_inc(h, "in-sessions");
|
||||||
|
ce->ce_next = bh->bh_ce_list;
|
||||||
bh->bh_ce_list = ce;
|
bh->bh_ce_list = ce;
|
||||||
return ce;
|
return ce;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ cli_auto_edit(clixon_handle h,
|
||||||
char *str;
|
char *str;
|
||||||
char *mtpoint = NULL;
|
char *mtpoint = NULL;
|
||||||
yang_stmt *yspec0;
|
yang_stmt *yspec0;
|
||||||
|
char *mtpoint2 = NULL;
|
||||||
|
|
||||||
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
|
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
|
||||||
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__);
|
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__);
|
||||||
|
|
@ -183,7 +184,6 @@ cli_auto_edit(clixon_handle h,
|
||||||
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (mtpoint){
|
if (mtpoint){
|
||||||
char *mtpoint2;
|
|
||||||
if ((mtpoint2 = strdup(mtpoint)) == NULL){
|
if ((mtpoint2 = strdup(mtpoint)) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "strdup");
|
clixon_err(OE_UNIX, errno, "strdup");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -204,6 +204,8 @@ cli_auto_edit(clixon_handle h,
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (mtpoint2)
|
||||||
|
free(mtpoint2);
|
||||||
if (api_path)
|
if (api_path)
|
||||||
free(api_path);
|
free(api_path);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,8 @@ mtpoint_paths(yang_stmt *yspec0,
|
||||||
free(api_path_fmt0);
|
free(api_path_fmt0);
|
||||||
if (nsc0)
|
if (nsc0)
|
||||||
cvec_free(nsc0);
|
cvec_free(nsc0);
|
||||||
|
if (xtop0)
|
||||||
|
xml_free(xtop0);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -513,7 +513,7 @@ netconf_notification_cb(int s,
|
||||||
if (xerr != NULL)
|
if (xerr != NULL)
|
||||||
xml_free(xerr);
|
xml_free(xerr);
|
||||||
if (cbmsg)
|
if (cbmsg)
|
||||||
free(cbmsg);
|
cbuf_free(cbmsg);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -528,7 +528,7 @@ restconf_accept_client(int fd,
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
restconf_socket *rsock;
|
restconf_socket *rsock;
|
||||||
clixon_handle h;
|
clixon_handle h;
|
||||||
int s;
|
int s = -1;
|
||||||
struct sockaddr from = {0,};
|
struct sockaddr from = {0,};
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
|
@ -568,7 +568,7 @@ restconf_accept_client(int fd,
|
||||||
clixon_err(OE_UNIX, errno, "calloc");
|
clixon_err(OE_UNIX, errno, "calloc");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0)
|
if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
clixon_debug(CLIXON_DBG_RESTCONF, "type:%s from:%s, dest:%s port:%hu",
|
clixon_debug(CLIXON_DBG_RESTCONF, "type:%s from:%s, dest:%s port:%hu",
|
||||||
rsock->rs_addrtype,
|
rsock->rs_addrtype,
|
||||||
|
|
@ -579,11 +579,14 @@ restconf_accept_client(int fd,
|
||||||
/* Accept SSL */
|
/* Accept SSL */
|
||||||
if (restconf_ssl_accept_client(h, s, rsock, NULL) < 0)
|
if (restconf_ssl_accept_client(h, s, rsock, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
s = -1;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
clixon_debug(CLIXON_DBG_RESTCONF, "retval:%d", retval);
|
clixon_debug(CLIXON_DBG_RESTCONF, "retval:%d", retval);
|
||||||
if (name)
|
if (name)
|
||||||
free(name);
|
free(name);
|
||||||
|
if (s != -1)
|
||||||
|
close(s);
|
||||||
return retval;
|
return retval;
|
||||||
} /* restconf_accept_client */
|
} /* restconf_accept_client */
|
||||||
|
|
||||||
|
|
@ -782,6 +785,7 @@ openssl_init_socket(clixon_handle h,
|
||||||
rsock->rs_ss = -1; /* Not applicable from callhome */
|
rsock->rs_ss = -1; /* Not applicable from callhome */
|
||||||
if (restconf_callhome_timer(rsock, 0) < 0)
|
if (restconf_callhome_timer(rsock, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
rsock = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* ss is a server socket that the clients connect to. The callback
|
/* ss is a server socket that the clients connect to. The callback
|
||||||
|
|
@ -789,9 +793,12 @@ openssl_init_socket(clixon_handle h,
|
||||||
rsock->rs_ss = ss;
|
rsock->rs_ss = ss;
|
||||||
if (clixon_event_reg_fd(rsock->rs_ss, restconf_accept_client, rsock, "restconf socket") < 0)
|
if (clixon_event_reg_fd(rsock->rs_ss, restconf_accept_client, rsock, "restconf socket") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
rsock = NULL;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (rsock)
|
||||||
|
free(rsock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ restconf_stream_data *
|
||||||
restconf_stream_data_new(restconf_conn *rc,
|
restconf_stream_data_new(restconf_conn *rc,
|
||||||
int32_t stream_id)
|
int32_t stream_id)
|
||||||
{
|
{
|
||||||
restconf_stream_data *sd;
|
restconf_stream_data *sd = NULL;
|
||||||
|
|
||||||
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
|
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "malloc");
|
clixon_err(OE_UNIX, errno, "malloc");
|
||||||
|
|
@ -100,23 +100,30 @@ restconf_stream_data_new(restconf_conn *rc,
|
||||||
sd->sd_fd = -1;
|
sd->sd_fd = -1;
|
||||||
if ((sd->sd_inbuf = cbuf_new()) == NULL){
|
if ((sd->sd_inbuf = cbuf_new()) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
return NULL;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((sd->sd_indata = cbuf_new()) == NULL){
|
if ((sd->sd_indata = cbuf_new()) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
return NULL;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
|
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||||
return NULL;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((sd->sd_outp_buf = cbuf_new()) == NULL){
|
if ((sd->sd_outp_buf = cbuf_new()) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
return NULL;
|
goto done;
|
||||||
}
|
}
|
||||||
sd->sd_conn = rc;
|
sd->sd_conn = rc;
|
||||||
INSQ(sd, rc->rc_streams);
|
INSQ(sd, rc->rc_streams);
|
||||||
|
ok:
|
||||||
return sd;
|
return sd;
|
||||||
|
done:
|
||||||
|
if (sd){
|
||||||
|
restconf_stream_free(sd);
|
||||||
|
sd = NULL;
|
||||||
|
}
|
||||||
|
goto ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Find restconf stream data
|
/*! Find restconf stream data
|
||||||
|
|
@ -870,7 +877,6 @@ restconf_http2_upgrade(restconf_conn *rc)
|
||||||
* @param[in] rc Restconf connection
|
* @param[in] rc Restconf connection
|
||||||
* @param[in] buf Input buffer
|
* @param[in] buf Input buffer
|
||||||
* @param[in] n Size of input buffer
|
* @param[in] n Size of input buffer
|
||||||
* @param[in] n Length of data in input buffer
|
|
||||||
* @param[out] readmore If set, read data again, do not continue processing
|
* @param[out] readmore If set, read data again, do not continue processing
|
||||||
* @retval 1 OK
|
* @retval 1 OK
|
||||||
* @retval 0 Socket closed, quit
|
* @retval 0 Socket closed, quit
|
||||||
|
|
@ -1015,9 +1021,9 @@ restconf_connection(int s,
|
||||||
#endif /* HAVE_HTTP1 */
|
#endif /* HAVE_HTTP1 */
|
||||||
#ifdef HAVE_LIBNGHTTP2
|
#ifdef HAVE_LIBNGHTTP2
|
||||||
case HTTP_2:
|
case HTTP_2:
|
||||||
if ((ret = restconf_http2_process(rc, buf, n, &readmore)) < 0)
|
|
||||||
goto done;
|
|
||||||
gettimeofday(&rc->rc_t, NULL); /* activity timer */
|
gettimeofday(&rc->rc_t, NULL); /* activity timer */
|
||||||
|
if ((ret = restconf_http2_process(rc, buf, n, &readmore)) < 0) // XXX frees rc
|
||||||
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
goto ok;
|
goto ok;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,8 @@ clixon_client_connect_netconf(clixon_handle h,
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (argv)
|
||||||
|
free(argv);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,6 +342,8 @@ clixon_client_connect_ssh(clixon_handle h,
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (argv)
|
||||||
|
free(argv);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -743,6 +743,8 @@ xmldb_print(clixon_handle h,
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (keys)
|
||||||
|
free(keys);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ xml_copy_bottom_recurse(cxobj *x0t,
|
||||||
cxobj *x0p = NULL;
|
cxobj *x0p = NULL;
|
||||||
cxobj *x1p = NULL;
|
cxobj *x1p = NULL;
|
||||||
cxobj *x1 = NULL;
|
cxobj *x1 = NULL;
|
||||||
|
int x1malloc = 0;
|
||||||
cxobj *x1a = NULL;
|
cxobj *x1a = NULL;
|
||||||
cxobj *x0a = NULL;
|
cxobj *x0a = NULL;
|
||||||
cxobj *x0k;
|
cxobj *x0k;
|
||||||
|
|
@ -168,6 +169,7 @@ xml_copy_bottom_recurse(cxobj *x0t,
|
||||||
if (x1 == NULL){ /* If not, create it and copy it one level only */
|
if (x1 == NULL){ /* If not, create it and copy it one level only */
|
||||||
if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
|
if ((x1 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
x1malloc++;
|
||||||
if (xml_copy_one(x0, x1) < 0)
|
if (xml_copy_one(x0, x1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Copy all attributes */
|
/* Copy all attributes */
|
||||||
|
|
@ -200,9 +202,12 @@ xml_copy_bottom_recurse(cxobj *x0t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*x1pp = x1;
|
*x1pp = x1;
|
||||||
|
x1 = NULL;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (x1 && x1malloc)
|
||||||
|
xml_free(x1);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,8 +118,8 @@ split_path(char *path,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
size_t allocated = PATH_CHUNKS;
|
size_t allocated = PATH_CHUNKS;
|
||||||
char *work; /* don't modify the original copy */
|
char *work = NULL; /* don't modify the original copy */
|
||||||
char **list;
|
char **list = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *new_element;
|
char *new_element;
|
||||||
|
|
@ -136,9 +136,7 @@ split_path(char *path,
|
||||||
list[len++] = new_element;
|
list[len++] = new_element;
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = strtok(ptr, "/");
|
ptr = strtok(ptr, "/");
|
||||||
|
|
||||||
while (ptr != NULL) {
|
while (ptr != NULL) {
|
||||||
if (len > allocated) {
|
if (len > allocated) {
|
||||||
/* we've run out of space, allocate a bigger list */
|
/* we've run out of space, allocate a bigger list */
|
||||||
|
|
@ -146,20 +144,20 @@ split_path(char *path,
|
||||||
if ((list = realloc(list, allocated * sizeof(char *))) == NULL)
|
if ((list = realloc(list, allocated * sizeof(char *))) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((new_element = strdup(ptr)) == NULL)
|
if ((new_element = strdup(ptr)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
list[len++] = new_element;
|
list[len++] = new_element;
|
||||||
|
|
||||||
ptr = strtok(NULL, "/");
|
ptr = strtok(NULL, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
*plist = list;
|
*plist = list;
|
||||||
|
list = NULL;
|
||||||
*plist_len = len;
|
*plist_len = len;
|
||||||
|
|
||||||
free(work);
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (list)
|
||||||
|
free(list);
|
||||||
|
if (work)
|
||||||
|
free(work);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,13 +234,15 @@ add_peer_node(dispatcher_entry_t *node,
|
||||||
new_node->peer_head = new_node;
|
new_node->peer_head = new_node;
|
||||||
|
|
||||||
return new_node;
|
return new_node;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* possibly adding to the list */
|
/* possibly adding to the list */
|
||||||
|
|
||||||
/* search for existing, or get tail end of list */
|
/* search for existing, or get tail end of list */
|
||||||
eptr = node->peer_head;
|
eptr = node->peer_head;
|
||||||
while (eptr->peer != NULL) {
|
while (eptr->peer != NULL) {
|
||||||
if (strcmp(eptr->node_name, name) == 0) {
|
if (strcmp(eptr->node_name, name) == 0) {
|
||||||
|
free(new_node);
|
||||||
return eptr;
|
return eptr;
|
||||||
}
|
}
|
||||||
eptr = eptr->peer;
|
eptr = eptr->peer;
|
||||||
|
|
@ -250,6 +250,7 @@ add_peer_node(dispatcher_entry_t *node,
|
||||||
|
|
||||||
// if eptr->node_name == name, we done
|
// if eptr->node_name == name, we done
|
||||||
if (strcmp(eptr->node_name, name) == 0) {
|
if (strcmp(eptr->node_name, name) == 0) {
|
||||||
|
free(new_node);
|
||||||
return eptr;
|
return eptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,7 +276,6 @@ add_peer_node(dispatcher_entry_t *node,
|
||||||
* @retval pointer Pointer to head of children list
|
* @retval pointer Pointer to head of children list
|
||||||
* @retval NULL Error
|
* @retval NULL Error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static dispatcher_entry_t *
|
static dispatcher_entry_t *
|
||||||
add_child_node(dispatcher_entry_t *node,
|
add_child_node(dispatcher_entry_t *node,
|
||||||
char *name)
|
char *name)
|
||||||
|
|
@ -382,13 +382,14 @@ int
|
||||||
dispatcher_register_handler(dispatcher_entry_t **root,
|
dispatcher_register_handler(dispatcher_entry_t **root,
|
||||||
dispatcher_definition *x)
|
dispatcher_definition *x)
|
||||||
{
|
{
|
||||||
|
int retval = -1;
|
||||||
char **split_path_list = NULL;
|
char **split_path_list = NULL;
|
||||||
size_t split_path_len = 0;
|
size_t split_path_len = 0;
|
||||||
dispatcher_entry_t *ptr;
|
dispatcher_entry_t *ptr;
|
||||||
|
|
||||||
if (*x->dd_path != '/') {
|
if (*x->dd_path != '/') {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -396,7 +397,7 @@ dispatcher_register_handler(dispatcher_entry_t **root,
|
||||||
* up to create the elements of the dispatcher table
|
* up to create the elements of the dispatcher table
|
||||||
*/
|
*/
|
||||||
if (split_path(x->dd_path, &split_path_list, &split_path_len) < 0)
|
if (split_path(x->dd_path, &split_path_list, &split_path_len) < 0)
|
||||||
return -1;
|
goto done;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the first element is always a peer to the top level
|
* the first element is always a peer to the top level
|
||||||
|
|
@ -411,7 +412,7 @@ dispatcher_register_handler(dispatcher_entry_t **root,
|
||||||
|
|
||||||
for (size_t i = 1; i < split_path_len; i++) {
|
for (size_t i = 1; i < split_path_len; i++) {
|
||||||
if ((ptr = add_child_node(ptr, split_path_list[i])) == NULL)
|
if ((ptr = add_child_node(ptr, split_path_list[i])) == NULL)
|
||||||
return -1;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* when we get here, ptr points at last entry added */
|
/* when we get here, ptr points at last entry added */
|
||||||
|
|
@ -420,8 +421,9 @@ dispatcher_register_handler(dispatcher_entry_t **root,
|
||||||
|
|
||||||
/* clean up */
|
/* clean up */
|
||||||
split_path_free(split_path_list, split_path_len);
|
split_path_free(split_path_list, split_path_len);
|
||||||
|
retval = 0;
|
||||||
return 0;
|
done:
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Call the handler and all its descendant handlers
|
/*! Call the handler and all its descendant handlers
|
||||||
|
|
|
||||||
|
|
@ -501,7 +501,7 @@ clixon_err_restore(void* handle)
|
||||||
if ((es = (struct err_state *)handle) != NULL){
|
if ((es = (struct err_state *)handle) != NULL){
|
||||||
_err_category = es->es_category;
|
_err_category = es->es_category;
|
||||||
_err_subnr = es->es_subnr;
|
_err_subnr = es->es_subnr;
|
||||||
strncpy(_err_reason, es->es_reason, ERR_STRLEN);
|
strncpy(_err_reason, es->es_reason, ERR_STRLEN-1);
|
||||||
free(es);
|
free(es);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -609,7 +609,7 @@ clixon_msg_rcv11(int s,
|
||||||
int eom = 0;
|
int eom = 0;
|
||||||
cxobj *xtop = NULL;
|
cxobj *xtop = NULL;
|
||||||
cxobj *xerr = NULL;
|
cxobj *xerr = NULL;
|
||||||
sigset_t oldsigset;
|
sigset_t oldsigset = {0,};
|
||||||
struct sigaction oldsigaction[32] = {{{0,},},};
|
struct sigaction oldsigaction[32] = {{{0,},},};
|
||||||
|
|
||||||
if ((cbmsg = cbuf_new()) == NULL){
|
if ((cbmsg = cbuf_new()) == NULL){
|
||||||
|
|
|
||||||
|
|
@ -601,6 +601,7 @@ clicon_rpc_get_config(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
xml_sort(xd); /* Ensure attr is first */
|
xml_sort(xd); /* Ensure attr is first */
|
||||||
*xt = xd;
|
*xt = xd;
|
||||||
|
xd = NULL;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -614,6 +615,8 @@ clicon_rpc_get_config(clixon_handle h,
|
||||||
xml_free(xret);
|
xml_free(xret);
|
||||||
if (msg)
|
if (msg)
|
||||||
free(msg);
|
free(msg);
|
||||||
|
if (xd)
|
||||||
|
xml_free(xd);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1271,6 +1274,7 @@ clicon_rpc_get_pageable_list(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
xml_sort(xd); /* Ensure attr is first */
|
xml_sort(xd); /* Ensure attr is first */
|
||||||
*xt = xd;
|
*xt = xd;
|
||||||
|
xd = NULL;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1284,6 +1288,8 @@ clicon_rpc_get_pageable_list(clixon_handle h,
|
||||||
xml_free(xret);
|
xml_free(xret);
|
||||||
if (msg)
|
if (msg)
|
||||||
free(msg);
|
free(msg);
|
||||||
|
if (xd)
|
||||||
|
xml_free(xd);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,21 @@ stream_find(clixon_handle h,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Delete event stream core components
|
||||||
|
*
|
||||||
|
* @param[in] es Event notification stream structure
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
stream_delete(event_stream_t *es)
|
||||||
|
{
|
||||||
|
if (es->es_name)
|
||||||
|
free(es->es_name);
|
||||||
|
if (es->es_description)
|
||||||
|
free(es->es_description);
|
||||||
|
free(es);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Add notification event stream
|
/*! Add notification event stream
|
||||||
*
|
*
|
||||||
* @param[in] h Clixon handle
|
* @param[in] h Clixon handle
|
||||||
|
|
@ -133,7 +148,7 @@ stream_add(clixon_handle h,
|
||||||
struct timeval *retention)
|
struct timeval *retention)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
event_stream_t *es;
|
event_stream_t *es = NULL;
|
||||||
|
|
||||||
if ((es = stream_find(h, name)) != NULL)
|
if ((es = stream_find(h, name)) != NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
|
|
@ -154,9 +169,12 @@ stream_add(clixon_handle h,
|
||||||
if (retention)
|
if (retention)
|
||||||
es->es_retention = *retention;
|
es->es_retention = *retention;
|
||||||
clicon_stream_append(h, es);
|
clicon_stream_append(h, es);
|
||||||
|
es = NULL;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (es)
|
||||||
|
stream_delete(es);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,10 +197,6 @@ stream_delete_all(clixon_handle h,
|
||||||
while ((es = clicon_stream(h)) != NULL){
|
while ((es = clicon_stream(h)) != NULL){
|
||||||
DELQ(es, head, event_stream_t *);
|
DELQ(es, head, event_stream_t *);
|
||||||
clicon_stream_set(h, head);
|
clicon_stream_set(h, head);
|
||||||
if (es->es_name)
|
|
||||||
free(es->es_name);
|
|
||||||
if (es->es_description)
|
|
||||||
free(es->es_description);
|
|
||||||
while ((ss = es->es_subscription) != NULL){
|
while ((ss = es->es_subscription) != NULL){
|
||||||
if (stream_ss_rm(h, es, ss, force) < 0)
|
if (stream_ss_rm(h, es, ss, force) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -193,7 +207,8 @@ stream_delete_all(clixon_handle h,
|
||||||
xml_free(r->r_xml);
|
xml_free(r->r_xml);
|
||||||
free(r);
|
free(r);
|
||||||
}
|
}
|
||||||
free(es);
|
if (stream_delete(es) < 0)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -857,7 +872,7 @@ stream_replay_trigger(clixon_handle h,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct replay_arg *ra;
|
struct replay_arg *ra = NULL;
|
||||||
|
|
||||||
if ((ra = malloc(sizeof(*ra))) == NULL){
|
if ((ra = malloc(sizeof(*ra))) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "malloc");
|
clixon_err(OE_UNIX, errno, "malloc");
|
||||||
|
|
@ -875,8 +890,11 @@ stream_replay_trigger(clixon_handle h,
|
||||||
if (clixon_event_reg_timeout(now, stream_replay_cb, ra,
|
if (clixon_event_reg_timeout(now, stream_replay_cb, ra,
|
||||||
"create-subscribtion stream replay") < 0)
|
"create-subscribtion stream replay") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
ra = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (ra)
|
||||||
|
free(ra);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ clixon_strsep2(char *str,
|
||||||
char *s1;
|
char *s1;
|
||||||
char *s2;
|
char *s2;
|
||||||
int nr = 0;
|
int nr = 0;
|
||||||
char *ptr;
|
char *ptr = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
s1 = str;
|
s1 = str;
|
||||||
|
|
@ -840,7 +840,7 @@ uri_str2cvec(char *string,
|
||||||
char *s;
|
char *s;
|
||||||
char *s0 = NULL;;
|
char *s0 = NULL;;
|
||||||
char *val; /* value */
|
char *val; /* value */
|
||||||
char *valu; /* unescaped value */
|
char *valu = NULL; /* unescaped value */
|
||||||
char *snext; /* next element in string */
|
char *snext; /* next element in string */
|
||||||
cvec *cvv = NULL;
|
cvec *cvv = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
|
|
@ -883,7 +883,10 @@ uri_str2cvec(char *string,
|
||||||
s++;
|
s++;
|
||||||
cv_name_set(cv, s);
|
cv_name_set(cv, s);
|
||||||
cv_string_set(cv, valu);
|
cv_string_set(cv, valu);
|
||||||
free(valu); valu = NULL;
|
if (valu) {
|
||||||
|
free(valu);
|
||||||
|
valu = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (strlen(s)){
|
if (strlen(s)){
|
||||||
|
|
@ -901,6 +904,8 @@ uri_str2cvec(char *string,
|
||||||
*cvp = cvv;
|
*cvp = cvv;
|
||||||
if (s0)
|
if (s0)
|
||||||
free(s0);
|
free(s0);
|
||||||
|
if (valu)
|
||||||
|
free(valu);
|
||||||
return retval;
|
return retval;
|
||||||
err:
|
err:
|
||||||
if (cvv){
|
if (cvv){
|
||||||
|
|
|
||||||
|
|
@ -1736,9 +1736,9 @@ xml_enumerate_get(cxobj *x)
|
||||||
|
|
||||||
/*! Get the first sub-node which is an XML body.
|
/*! Get the first sub-node which is an XML body.
|
||||||
*
|
*
|
||||||
* @param[in] xn xml tree node
|
* @param[in] xn XML tree node
|
||||||
* @retval The returned body as a pointer to the name string
|
* @retval body The returned body as a pointer to the name string
|
||||||
* @retval NULL if no such node or no body in found node
|
* @retval NULL If no such node or no body in found node
|
||||||
* Note, make a copy of the return value to use it properly
|
* Note, make a copy of the return value to use it properly
|
||||||
* @see xml_find_body
|
* @see xml_find_body
|
||||||
* Explaining picture:
|
* Explaining picture:
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,11 @@ xml_default_create1(yang_stmt *y,
|
||||||
if (xml_addsub(xt, xc) < 0)
|
if (xml_addsub(xt, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
*xcp = xc;
|
*xcp = xc;
|
||||||
|
xc = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (xc)
|
||||||
|
xml_free(xc);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1045,8 +1045,10 @@ xpath_traverse_canonical(xpath_tree *xs,
|
||||||
if (xml_nsctx_add(nsc1, prefix1, namespace) < 0)
|
if (xml_nsctx_add(nsc1, prefix1, namespace) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (prefix0==NULL || strcmp(prefix0, prefix1) != 0){
|
if (prefix0==NULL || strcmp(prefix0, prefix1) != 0){
|
||||||
if (xs->xs_s0)
|
if (xs->xs_s0){
|
||||||
free(xs->xs_s0);
|
free(xs->xs_s0);
|
||||||
|
xs->xs_s0 = NULL;
|
||||||
|
}
|
||||||
if ((xs->xs_s0 = strdup(prefix1)) == NULL){
|
if ((xs->xs_s0 = strdup(prefix1)) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "strdup");
|
clixon_err(OE_UNIX, errno, "strdup");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -621,8 +621,11 @@ xp_logop(xp_ctx *xc1,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
*xrp = xr;
|
*xrp = xr;
|
||||||
|
xr = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (xr)
|
||||||
|
ctx_free(xr);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -684,8 +687,11 @@ xp_numop(xp_ctx *xc1,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
*xrp = xr;
|
*xrp = xr;
|
||||||
|
xr = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (xr)
|
||||||
|
ctx_free(xr);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1111,8 +1117,11 @@ xp_union(xp_ctx *xc1,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
*xrp = xr;
|
*xrp = xr;
|
||||||
|
xr = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (xr)
|
||||||
|
ctx_free(xr);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,8 @@ xp_function_derived_from(xp_ctx *xc,
|
||||||
ctx_free(xr0);
|
ctx_free(xr0);
|
||||||
if (xr1)
|
if (xr1)
|
||||||
ctx_free(xr1);
|
ctx_free(xr1);
|
||||||
|
if (xr)
|
||||||
|
ctx_free(xr);
|
||||||
if (identity)
|
if (identity)
|
||||||
free(identity);
|
free(identity);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -568,12 +570,15 @@ xp_function_name(xp_ctx *xc,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*xrp = xr;
|
*xrp = xr;
|
||||||
|
xr = NULL;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (xr0)
|
if (xr0)
|
||||||
ctx_free(xr0);
|
ctx_free(xr0);
|
||||||
if (s0)
|
if (s0)
|
||||||
free(s0);
|
free(s0);
|
||||||
|
if (xr)
|
||||||
|
ctx_free(xr);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1014,18 +1014,10 @@ ys_replace(yang_stmt *yorig,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
yang_stmt *yp; /* parent */
|
yang_stmt *yp; /* parent */
|
||||||
yang_stmt *yc; /* child */
|
|
||||||
|
|
||||||
yp = yang_parent_get(yorig);
|
yp = yang_parent_get(yorig);
|
||||||
/* Remove old yangs all children */
|
/* Remove old yangs all children */
|
||||||
yc = NULL;
|
ys_freechildren(yorig);
|
||||||
while ((yc = yn_each(yorig, yc)) != NULL)
|
|
||||||
ys_free(yc);
|
|
||||||
if (yorig->ys_stmt){
|
|
||||||
free(yorig->ys_stmt);
|
|
||||||
yorig->ys_stmt = NULL;
|
|
||||||
yorig->ys_len = 0;
|
|
||||||
}
|
|
||||||
ys_free1(yorig, 0); /* Remove all in yold except the actual object */
|
ys_free1(yorig, 0); /* Remove all in yold except the actual object */
|
||||||
if (ys_cp(yorig, yfrom) < 0)
|
if (ys_cp(yorig, yfrom) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue