diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bff6ce83..7e2cc327 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - name: install example run: (cd example; sudo make install) - docker-alpine-tests-a-j: + docker-alpine-tests-a-l: runs-on: ubuntu-latest defaults: run: @@ -79,9 +79,9 @@ jobs: - name: start container run: ./start.sh - 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 defaults: run: @@ -110,7 +110,7 @@ jobs: - name: start container run: ./start.sh - 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: runs-on: ubuntu-latest diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index b22d1fa5..0ffce232 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -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; diff --git a/apps/backend/backend_socket.c b/apps/backend/backend_socket.c index 58e78fe5..a63d4f9e 100644 --- a/apps/backend/backend_socket.c +++ b/apps/backend/backend_socket.c @@ -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; diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index f228e76d..c54f5b17 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -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; } diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 4dbb408d..3b7a9d56 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -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>*, )", __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; diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index e8fb157f..c525b06e 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -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; } diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index 58a454b5..b6eb2393 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -513,7 +513,7 @@ netconf_notification_cb(int s, if (xerr != NULL) xml_free(xerr); if (cbmsg) - free(cbmsg); + cbuf_free(cbmsg); return retval; } diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index 3edbb2df..3b11113a 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -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; } diff --git a/apps/restconf/restconf_native.c b/apps/restconf/restconf_native.c index 3c7d555d..7569b88e 100644 --- a/apps/restconf/restconf_native.c +++ b/apps/restconf/restconf_native.c @@ -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; diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c index 800d2795..489f8182 100644 --- a/lib/src/clixon_client.c +++ b/lib/src/clixon_client.c @@ -299,6 +299,8 @@ clixon_client_connect_netconf(clixon_handle h, } retval = 0; done: + if (argv) + free(argv); return retval; } @@ -340,6 +342,8 @@ clixon_client_connect_ssh(clixon_handle h, } retval = 0; done: + if (argv) + free(argv); return retval; } diff --git a/lib/src/clixon_datastore.c b/lib/src/clixon_datastore.c index a2d34293..80d2efd1 100644 --- a/lib/src/clixon_datastore.c +++ b/lib/src/clixon_datastore.c @@ -743,6 +743,8 @@ xmldb_print(clixon_handle h, } retval = 0; done: + if (keys) + free(keys); return retval; } diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index f0fd04a6..230e41f9 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -142,6 +142,7 @@ xml_copy_bottom_recurse(cxobj *x0t, cxobj *x0p = NULL; cxobj *x1p = NULL; cxobj *x1 = NULL; + int x1malloc = 0; cxobj *x1a = NULL; cxobj *x0a = NULL; 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 = xml_new(xml_name(x0), x1p, CX_ELMNT)) == NULL) goto done; + x1malloc++; if (xml_copy_one(x0, x1) < 0) goto done; /* Copy all attributes */ @@ -200,9 +202,12 @@ xml_copy_bottom_recurse(cxobj *x0t, } } *x1pp = x1; + x1 = NULL; ok: retval = 0; done: + if (x1 && x1malloc) + xml_free(x1); return retval; } diff --git a/lib/src/clixon_dispatcher.c b/lib/src/clixon_dispatcher.c index b8394f3e..3b67d4f3 100644 --- a/lib/src/clixon_dispatcher.c +++ b/lib/src/clixon_dispatcher.c @@ -118,8 +118,8 @@ split_path(char *path, { int retval = -1; size_t allocated = PATH_CHUNKS; - char *work; /* don't modify the original copy */ - char **list; + char *work = NULL; /* don't modify the original copy */ + char **list = NULL; size_t len = 0; char *ptr; char *new_element; @@ -136,9 +136,7 @@ split_path(char *path, list[len++] = new_element; ptr++; } - ptr = strtok(ptr, "/"); - while (ptr != NULL) { if (len > allocated) { /* 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) goto done; } - if ((new_element = strdup(ptr)) == NULL) goto done; list[len++] = new_element; - ptr = strtok(NULL, "/"); } - *plist = list; + list = NULL; *plist_len = len; - - free(work); retval = 0; done: + if (list) + free(list); + if (work) + free(work); return retval; } @@ -236,13 +234,15 @@ add_peer_node(dispatcher_entry_t *node, new_node->peer_head = new_node; return new_node; - } else { + } + else { /* possibly adding to the list */ /* search for existing, or get tail end of list */ eptr = node->peer_head; while (eptr->peer != NULL) { if (strcmp(eptr->node_name, name) == 0) { + free(new_node); return eptr; } eptr = eptr->peer; @@ -250,6 +250,7 @@ add_peer_node(dispatcher_entry_t *node, // if eptr->node_name == name, we done if (strcmp(eptr->node_name, name) == 0) { + free(new_node); return eptr; } @@ -275,7 +276,6 @@ add_peer_node(dispatcher_entry_t *node, * @retval pointer Pointer to head of children list * @retval NULL Error */ - static dispatcher_entry_t * add_child_node(dispatcher_entry_t *node, char *name) @@ -382,13 +382,14 @@ int dispatcher_register_handler(dispatcher_entry_t **root, dispatcher_definition *x) { + int retval = -1; char **split_path_list = NULL; size_t split_path_len = 0; dispatcher_entry_t *ptr; if (*x->dd_path != '/') { 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 */ 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 @@ -411,7 +412,7 @@ dispatcher_register_handler(dispatcher_entry_t **root, for (size_t i = 1; i < split_path_len; i++) { 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 */ @@ -420,8 +421,9 @@ dispatcher_register_handler(dispatcher_entry_t **root, /* clean up */ split_path_free(split_path_list, split_path_len); - - return 0; + retval = 0; + done: + return retval; } /*! Call the handler and all its descendant handlers diff --git a/lib/src/clixon_err.c b/lib/src/clixon_err.c index 15ecb25e..07d4c904 100644 --- a/lib/src/clixon_err.c +++ b/lib/src/clixon_err.c @@ -501,7 +501,7 @@ clixon_err_restore(void* handle) if ((es = (struct err_state *)handle) != NULL){ _err_category = es->es_category; _err_subnr = es->es_subnr; - strncpy(_err_reason, es->es_reason, ERR_STRLEN); + strncpy(_err_reason, es->es_reason, ERR_STRLEN-1); free(es); } return 0; diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index d3da591c..be1f57e3 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -609,7 +609,7 @@ clixon_msg_rcv11(int s, int eom = 0; cxobj *xtop = NULL; cxobj *xerr = NULL; - sigset_t oldsigset; + sigset_t oldsigset = {0,}; struct sigaction oldsigaction[32] = {{{0,},},}; if ((cbmsg = cbuf_new()) == NULL){ diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 62378e78..8ac29d5e 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -601,6 +601,7 @@ clicon_rpc_get_config(clixon_handle h, goto done; xml_sort(xd); /* Ensure attr is first */ *xt = xd; + xd = NULL; } retval = 0; done: @@ -614,6 +615,8 @@ clicon_rpc_get_config(clixon_handle h, xml_free(xret); if (msg) free(msg); + if (xd) + xml_free(xd); return retval; } @@ -1271,6 +1274,7 @@ clicon_rpc_get_pageable_list(clixon_handle h, goto done; xml_sort(xd); /* Ensure attr is first */ *xt = xd; + xd = NULL; } retval = 0; done: @@ -1284,6 +1288,8 @@ clicon_rpc_get_pageable_list(clixon_handle h, xml_free(xret); if (msg) free(msg); + if (xd) + xml_free(xd); return retval; } diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index 8c7d1565..4f708bbc 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -115,6 +115,21 @@ stream_find(clixon_handle h, 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 * * @param[in] h Clixon handle @@ -133,7 +148,7 @@ stream_add(clixon_handle h, struct timeval *retention) { int retval = -1; - event_stream_t *es; + event_stream_t *es = NULL; if ((es = stream_find(h, name)) != NULL) goto ok; @@ -154,9 +169,12 @@ stream_add(clixon_handle h, if (retention) es->es_retention = *retention; clicon_stream_append(h, es); + es = NULL; ok: retval = 0; done: + if (es) + stream_delete(es); return retval; } @@ -179,10 +197,6 @@ stream_delete_all(clixon_handle h, while ((es = clicon_stream(h)) != NULL){ DELQ(es, head, event_stream_t *); 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){ if (stream_ss_rm(h, es, ss, force) < 0) goto done; @@ -193,7 +207,8 @@ stream_delete_all(clixon_handle h, xml_free(r->r_xml); free(r); } - free(es); + if (stream_delete(es) < 0) + goto done; } retval = 0; done: @@ -857,7 +872,7 @@ stream_replay_trigger(clixon_handle h, { int retval = -1; struct timeval now; - struct replay_arg *ra; + struct replay_arg *ra = NULL; if ((ra = malloc(sizeof(*ra))) == NULL){ 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, "create-subscribtion stream replay") < 0) goto done; + ra = NULL; retval = 0; done: + if (ra) + free(ra); return retval; } diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index dfcffa75..23453526 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -147,7 +147,7 @@ clixon_strsep2(char *str, char *s1; char *s2; int nr = 0; - char *ptr; + char *ptr = NULL; int i; s1 = str; @@ -840,7 +840,7 @@ uri_str2cvec(char *string, char *s; char *s0 = NULL;; char *val; /* value */ - char *valu; /* unescaped value */ + char *valu = NULL; /* unescaped value */ char *snext; /* next element in string */ cvec *cvv = NULL; cg_var *cv; @@ -883,7 +883,10 @@ uri_str2cvec(char *string, s++; cv_name_set(cv, s); cv_string_set(cv, valu); - free(valu); valu = NULL; + if (valu) { + free(valu); + valu = NULL; + } } else{ if (strlen(s)){ @@ -901,6 +904,8 @@ uri_str2cvec(char *string, *cvp = cvv; if (s0) free(s0); + if (valu) + free(valu); return retval; err: if (cvv){ diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 376449be..0c46bccf 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -1736,9 +1736,9 @@ xml_enumerate_get(cxobj *x) /*! Get the first sub-node which is an XML body. * - * @param[in] xn xml tree node - * @retval The returned body as a pointer to the name string - * @retval NULL if no such node or no body in found node + * @param[in] xn XML tree node + * @retval body The returned body as a pointer to the name string + * @retval NULL If no such node or no body in found node * Note, make a copy of the return value to use it properly * @see xml_find_body * Explaining picture: diff --git a/lib/src/clixon_xml_default.c b/lib/src/clixon_xml_default.c index 74008cc1..028cae59 100644 --- a/lib/src/clixon_xml_default.c +++ b/lib/src/clixon_xml_default.c @@ -86,11 +86,11 @@ xml_default_create1(yang_stmt *y, cxobj *xt, cxobj **xcp) { - int retval = -1; - char *namespace; - char *prefix; - int ret; - cxobj *xc = NULL; + int retval = -1; + char *namespace; + char *prefix; + int ret; + cxobj *xc = NULL; if ((xc = xml_new(yang_argument_get(y), NULL, CX_ELMNT)) == NULL) goto done; @@ -116,8 +116,11 @@ xml_default_create1(yang_stmt *y, if (xml_addsub(xt, xc) < 0) goto done; *xcp = xc; + xc = NULL; retval = 0; done: + if (xc) + xml_free(xc); return retval; } diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index e6b56f8a..40f510fc 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -1045,8 +1045,10 @@ xpath_traverse_canonical(xpath_tree *xs, if (xml_nsctx_add(nsc1, prefix1, namespace) < 0) goto done; if (prefix0==NULL || strcmp(prefix0, prefix1) != 0){ - if (xs->xs_s0) + if (xs->xs_s0){ free(xs->xs_s0); + xs->xs_s0 = NULL; + } if ((xs->xs_s0 = strdup(prefix1)) == NULL){ clixon_err(OE_UNIX, errno, "strdup"); goto done; diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index ef80ec1f..c00593cc 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -621,8 +621,11 @@ xp_logop(xp_ctx *xc1, goto done; } *xrp = xr; + xr = NULL; retval = 0; done: + if (xr) + ctx_free(xr); return retval; } @@ -684,8 +687,11 @@ xp_numop(xp_ctx *xc1, goto done; } *xrp = xr; + xr = NULL; retval = 0; done: + if (xr) + ctx_free(xr); return retval; } @@ -1111,8 +1117,11 @@ xp_union(xp_ctx *xc1, goto done; } *xrp = xr; + xr = NULL; retval = 0; done: + if (xr) + ctx_free(xr); return retval; } diff --git a/lib/src/clixon_xpath_function.c b/lib/src/clixon_xpath_function.c index 03ac6893..bd1881d4 100644 --- a/lib/src/clixon_xpath_function.c +++ b/lib/src/clixon_xpath_function.c @@ -375,6 +375,8 @@ xp_function_derived_from(xp_ctx *xc, ctx_free(xr0); if (xr1) ctx_free(xr1); + if (xr) + ctx_free(xr); if (identity) free(identity); return retval; @@ -568,12 +570,15 @@ xp_function_name(xp_ctx *xc, break; } *xrp = xr; + xr = NULL; retval = 0; done: if (xr0) ctx_free(xr0); if (s0) free(s0); + if (xr) + ctx_free(xr); return retval; } diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 66d2ba76..4d6bfc43 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -1014,18 +1014,10 @@ ys_replace(yang_stmt *yorig, { int retval = -1; yang_stmt *yp; /* parent */ - yang_stmt *yc; /* child */ yp = yang_parent_get(yorig); /* Remove old yangs all children */ - yc = NULL; - 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_freechildren(yorig); ys_free1(yorig, 0); /* Remove all in yold except the actual object */ if (ys_cp(yorig, yfrom) < 0) goto done;