From d69cf8e89b3d7e182d2ef55a8f9b5e90b38fac5b Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Mon, 10 Jun 2024 20:22:22 +0530 Subject: src/jobs: clean up --- include/jobs.h | 2 +- src/jobs.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/jobs.h b/include/jobs.h index 571be0d..41bfa57 100644 --- a/include/jobs.h +++ b/include/jobs.h @@ -9,7 +9,7 @@ struct output { LIST_HEAD(job_dlist, job); struct job { - char *drv_path, *name; + char *name, *drv_path; struct output_dlist outputs; struct job_dlist deps; diff --git a/src/jobs.c b/src/jobs.c index 7893632..78b52cc 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -9,12 +9,13 @@ #include "util.h" static int job_output_insert(struct job *j, char *name, char *store_path); +static void output_free(struct output *output); int job_read(FILE *stream, struct job **job) { int ret; - cJSON *root, *temp, *input_drvs, *array; struct job *dep_job; + cJSON *root, *temp, *input_drvs, *array; char *name = NULL; char *out_name = NULL; char *drv_path = NULL; @@ -82,8 +83,9 @@ int job_read(FILE *stream, struct job **job) } } - LIST_INSERT_HEAD(&(*job)->deps, dep_job, dlist); drv_path = NULL; + out_name = NULL; + LIST_INSERT_HEAD(&(*job)->deps, dep_job, dlist); } out_free: @@ -93,11 +95,12 @@ out_free: print_err("%s", "Invalid JSON"); free(name); free(drv_path); + free(out_name); } return ret; } -void output_free(struct output *output) +static void output_free(struct output *output) { if (output == NULL) return; @@ -118,12 +121,14 @@ void job_free(struct job *job) free(job->name); free(job->drv_path); - free(job); + LIST_FOREACH (o, &job->outputs, dlist) output_free(o); LIST_FOREACH (j, &job->deps, dlist) job_free(j); + + free(job); } static int job_output_insert(struct job *j, char *name, char *store_path) @@ -148,7 +153,7 @@ int job_new(struct job **j, char *name, char *drv_path) struct job *job; job = malloc(sizeof(*job)); - if (*j == NULL) { + if (job == NULL) { print_err("%s", strerror(errno)); return -errno; } -- cgit v1.2.3