Skip to content

Commit

Permalink
Various memory and file resource cleanup after valgrind tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Jun 23, 2024
1 parent 78cd42c commit c2841d6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/backend/clixon_backend_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ backend_client_delete(clixon_handle h,
free(ce->ce_transport);
if (ce->ce_source_host)
free(ce->ce_source_host);
ce->ce_next = NULL;
free(ce);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/clixon_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ clixon_proc_socket(clixon_handle h,
clixon_err(OE_UNIX, EINVAL, "argv[0] is NULL");
goto done;
}

clixon_debug(CLIXON_DBG_PROC, "%s...", argv[0]);

for (argc = 0; argv[argc] != NULL; ++argc)
;
if ((flattened = clicon_strjoin(argc, argv, "', '")) == NULL){
Expand Down Expand Up @@ -254,6 +252,7 @@ clixon_proc_socket(clixon_handle h,
signal(SIGTSTP, SIG_IGN);

close(sp[0]);
close(sperr[0]);
close(0);
if (dup2(sp[1], STDIN_FILENO) < 0){
clixon_err(OE_UNIX, errno, "dup2(STDIN)");
Expand All @@ -273,15 +272,17 @@ clixon_proc_socket(clixon_handle h,
}
close(sperr[1]);
}
close(sperr[1]);
if (execvp(argv[0], argv) < 0){
clixon_err(OE_UNIX, errno, "execvp(%s)", argv[0]);
return -1;
}
exit(-1); /* Shouldnt reach here */
}
clixon_debug(CLIXON_DBG_PROC | CLIXON_DBG_DETAIL, "child %u sock %d", child, sp[0]);
clixon_debug(CLIXON_DBG_PROC, "child %u sock %d", child, sp[0]);
/* Parent */
close(sp[1]);
close(sperr[1]);
*pid = child;
*sock = sp[0];
if (sockerr)
Expand All @@ -308,7 +309,6 @@ clixon_proc_socket_close(pid_t pid,
int status;

clixon_debug(CLIXON_DBG_PROC, "pid %u sock %d", pid, sock);

if (sock != -1)
close(sock); /* usually kills */
kill(pid, SIGTERM);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/clixon_xpath_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ ctx2number(xp_ctx *xc,
}

/*! Replace a nodeset of a XPath context with a new nodeset
*
* @param[in] vec XML vector, is consumed
* @param[in] veclen
*/
int
ctx_nodeset_replace(xp_ctx *xc,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/clixon_xpath_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ xp_eval_step(xp_ctx *xc0,
}
}
ctx_nodeset_replace(xc, vec, veclen);
if (vec)
vec = NULL;
break;
case A_DESCENDANT_OR_SELF:
for (i=0; i<xc->xc_size; i++){
Expand Down Expand Up @@ -705,6 +707,7 @@ xp_numop(xp_ctx *xc1,
* Move to clixon_xml.c?
* As a side-effect sets the cache.
* Clear cache with xml_cv_set(x, NULL)
* @see xml_cv_cache.c duplicated function
*/
static int
xml_cv_cache(cxobj *x,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/clixon_xpath_optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ xpath_optimize_check(xpath_tree *xs,
else if ((ret = xpath_list_optimize_fn(xs, xv, xvec)) < 0)
goto done;
else if (ret == 1){
if (xvec0 && *xvec0){
free(*xvec0);
*xvec0 = NULL;
}
if (clixon_xvec_extract(xvec, xvec0, xlen0, NULL) < 0){
goto done;
}
Expand Down
7 changes: 2 additions & 5 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,8 @@ yang_ref_dec(yang_stmt *ys)
{
int retval = -1;

if (ys->ys_ref <= 0){
clixon_err(OE_YANG, 0, "reference count is %d cannot decrement", ys->ys_ref);
goto done;
}
ys->ys_ref--;
if (ys->ys_ref > 0)
ys->ys_ref--;
retval = 0;
done:
return retval;
Expand Down
3 changes: 0 additions & 3 deletions lib/src/clixon_yang_schema_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,7 @@ yang_mount_set(yang_stmt *y,
if ((cvv = yang_cvec_get(y)) != NULL &&
(cv = cvec_find(cvv, xpath)) != NULL &&
(yspec0 = cv_void_get(cv)) != NULL){
#if 0 /* Problematic to free yang specs here, upper layers should handle it? */
ys_free(yspec0);
#endif
yang_ref_dec(yspec0);
cv_void_set(cv, NULL);
}
else if ((cv = yang_cvec_add(y, CGV_VOID, xpath)) == NULL)
Expand Down

0 comments on commit c2841d6

Please sign in to comment.