Skip to content

Commit 70ec65f

Browse files
committed
job-exec: fix memory leak on error path
Problem: if exec_init() fails to add the exec context to the bulk_exec aux container, the exec context is leaked. Free the exec context in that case.
1 parent f55bc1e commit 70ec65f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/modules/job-exec/exec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ struct exec_ctx {
5656

5757
static void exec_ctx_destroy (struct exec_ctx *tc)
5858
{
59-
free (tc);
59+
if (tc) {
60+
int saved_errno = errno;
61+
free (tc);
62+
errno = saved_errno;
63+
}
6064
}
6165

6266
static struct exec_ctx *exec_ctx_create (json_t *jobspec)
@@ -338,6 +342,7 @@ static int exec_init (struct jobinfo *job)
338342
}
339343
if (bulk_exec_aux_set (exec, "ctx", ctx,
340344
(flux_free_f) exec_ctx_destroy) < 0) {
345+
exec_ctx_destroy (ctx);
341346
flux_log_error (job->h, "exec_init: bulk_exec_aux_set");
342347
goto err;
343348
}

0 commit comments

Comments
 (0)