Fixes after coverity static analysis

This commit is contained in:
Olof hagsand 2024-03-03 17:05:36 +01:00
parent d94b4f5b7c
commit a1badc312e
24 changed files with 148 additions and 70 deletions

View file

@ -285,10 +285,10 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
char *xpath,
cxobj **xp)
{
int retval = -1;
plgstatedata_t *fn; /* Plugin statedata fn */
cxobj *x = NULL;
void *wh = NULL;
int retval = -1;
plgstatedata_t *fn; /* Plugin statedata fn */
cxobj *x = NULL;
void *wh = NULL;
if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
@ -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)
goto done;
}
if (xp && x)
if (xp && x){
*xp = x;
x = NULL;
}
retval = 1;
done:
if (x)
xml_free(x);
return retval;
fail:
retval = 0;

View file

@ -232,7 +232,7 @@ backend_accept_client(int fd,
{
int retval = -1;
clixon_handle h = (clixon_handle)arg;
int s;
int s = -1;
struct sockaddr from = {0,};
socklen_t len;
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)
goto done;
s = -1;
retval = 0;
done:
if (s != -1)
close(s);
if (name)
free(name);
return retval;

View file

@ -142,7 +142,7 @@ backend_client_add(clixon_handle h,
struct sockaddr *addr)
{
struct backend_handle *bh = handle(h);
struct client_entry *ce;
struct client_entry *ce = NULL;
if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){
clixon_err(OE_PLUGIN, errno, "malloc");
@ -151,15 +151,16 @@ backend_client_add(clixon_handle h,
memset(ce, 0, sizeof(*ce));
ce->ce_nr = bh->bh_ce_nr++; /* Session-id ? */
memcpy(&ce->ce_addr, addr, sizeof(*addr));
ce->ce_next = bh->bh_ce_list;
ce->ce_handle = h;
if (clicon_session_id_get(h, &ce->ce_id) < 0){
clixon_err(OE_NETCONF, ENOENT, "session_id not set");
free(ce);
return NULL;
}
clicon_session_id_set(h, ce->ce_id + 1);
gettimeofday(&ce->ce_time, NULL);
netconf_monitoring_counter_inc(h, "in-sessions");
ce->ce_next = bh->bh_ce_list;
bh->bh_ce_list = ce;
return ce;
}

View file

@ -129,6 +129,7 @@ cli_auto_edit(clixon_handle h,
char *str;
char *mtpoint = NULL;
yang_stmt *yspec0;
char *mtpoint2 = NULL;
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
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)
goto done;
if (mtpoint){
char *mtpoint2;
if ((mtpoint2 = strdup(mtpoint)) == NULL){
clixon_err(OE_UNIX, errno, "strdup");
goto done;
@ -204,6 +204,8 @@ cli_auto_edit(clixon_handle h,
}
retval = 0;
done:
if (mtpoint2)
free(mtpoint2);
if (api_path)
free(api_path);
return retval;

View file

@ -356,6 +356,8 @@ mtpoint_paths(yang_stmt *yspec0,
free(api_path_fmt0);
if (nsc0)
cvec_free(nsc0);
if (xtop0)
xml_free(xtop0);
return retval;
}

View file

@ -513,7 +513,7 @@ netconf_notification_cb(int s,
if (xerr != NULL)
xml_free(xerr);
if (cbmsg)
free(cbmsg);
cbuf_free(cbmsg);
return retval;
}

View file

@ -528,7 +528,7 @@ restconf_accept_client(int fd,
int retval = -1;
restconf_socket *rsock;
clixon_handle h;
int s;
int s = -1;
struct sockaddr from = {0,};
socklen_t len;
char *name = NULL;
@ -568,7 +568,7 @@ restconf_accept_client(int fd,
clixon_err(OE_UNIX, errno, "calloc");
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;
clixon_debug(CLIXON_DBG_RESTCONF, "type:%s from:%s, dest:%s port:%hu",
rsock->rs_addrtype,
@ -579,11 +579,14 @@ restconf_accept_client(int fd,
/* Accept SSL */
if (restconf_ssl_accept_client(h, s, rsock, NULL) < 0)
goto done;
s = -1;
retval = 0;
done:
clixon_debug(CLIXON_DBG_RESTCONF, "retval:%d", retval);
if (name)
free(name);
if (s != -1)
close(s);
return retval;
} /* restconf_accept_client */
@ -782,6 +785,7 @@ openssl_init_socket(clixon_handle h,
rsock->rs_ss = -1; /* Not applicable from callhome */
if (restconf_callhome_timer(rsock, 0) < 0)
goto done;
rsock = NULL;
}
else {
/* 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;
if (clixon_event_reg_fd(rsock->rs_ss, restconf_accept_client, rsock, "restconf socket") < 0)
goto done;
rsock = NULL;
}
retval = 0;
done:
if (rsock)
free(rsock);
return retval;
}

View file

@ -89,7 +89,7 @@ restconf_stream_data *
restconf_stream_data_new(restconf_conn *rc,
int32_t stream_id)
{
restconf_stream_data *sd;
restconf_stream_data *sd = NULL;
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
clixon_err(OE_UNIX, errno, "malloc");
@ -100,23 +100,30 @@ restconf_stream_data_new(restconf_conn *rc,
sd->sd_fd = -1;
if ((sd->sd_inbuf = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL;
goto done;
}
if ((sd->sd_indata = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL;
goto done;
}
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
clixon_err(OE_UNIX, errno, "cvec_new");
return NULL;
goto done;
}
if ((sd->sd_outp_buf = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL;
goto done;
}
sd->sd_conn = rc;
INSQ(sd, rc->rc_streams);
ok:
return sd;
done:
if (sd){
restconf_stream_free(sd);
sd = NULL;
}
goto ok;
}
/*! Find restconf stream data
@ -870,7 +877,6 @@ restconf_http2_upgrade(restconf_conn *rc)
* @param[in] rc Restconf connection
* @param[in] buf 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
* @retval 1 OK
* @retval 0 Socket closed, quit
@ -1015,9 +1021,9 @@ restconf_connection(int s,
#endif /* HAVE_HTTP1 */
#ifdef HAVE_LIBNGHTTP2
case HTTP_2:
if ((ret = restconf_http2_process(rc, buf, n, &readmore)) < 0)
goto done;
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)
goto ok;
break;