Skip to content

Commit 9d2db4d

Browse files
kr-tcasaroli
authored andcommitted
fix(context): duplicate the workdir instead of setting it
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent 70d32ef commit 9d2db4d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/ocre/context.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LOG_MODULE_REGISTER(context, CONFIG_OCRE_LOG_LEVEL);
3030

3131
struct ocre_context {
3232
pthread_mutex_t mutex;
33-
const char *working_directory;
33+
char *working_directory;
3434
struct container_node *containers;
3535
};
3636

@@ -98,7 +98,10 @@ struct ocre_context *ocre_context_create(const char *workdir)
9898

9999
/* Set working directory */
100100

101-
context->working_directory = workdir;
101+
context->working_directory = strdup(workdir);
102+
if (!context->working_directory) {
103+
goto error;
104+
}
102105

103106
/* Initialize containers list */
104107

@@ -108,6 +111,7 @@ struct ocre_context *ocre_context_create(const char *workdir)
108111

109112
error:
110113
free(context);
114+
free(context->working_directory);
111115

112116
return NULL;
113117
};
@@ -163,6 +167,7 @@ int ocre_context_destroy(struct ocre_context *context)
163167
return -1;
164168
}
165169

170+
free(context->working_directory);
166171
free(context);
167172

168173
return 0;

0 commit comments

Comments
 (0)