From a41dd6c79f542925c5db7f1ee51d27b65ba832ec Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 24 May 2019 17:25:31 +0200 Subject: [PATCH] Make owned filename a pointer-to-non-const The file handler owns the filename string, so it needs to free it. Therefore, it should not be a pointer-to-const. --- app/src/file_handler.c | 8 ++++---- app/src/file_handler.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/file_handler.c b/app/src/file_handler.c index c4366691..c72b598d 100644 --- a/app/src/file_handler.c +++ b/app/src/file_handler.c @@ -10,11 +10,11 @@ struct request { file_handler_action_t action; - const char *file; + char *file; }; static struct request * -request_new(file_handler_action_t action, const char *file) { +request_new(file_handler_action_t action, char *file) { struct request *req = SDL_malloc(sizeof(*req)); if (!req) { return NULL; @@ -29,7 +29,7 @@ request_free(struct request *req) { if (!req) { return; } - SDL_free((void *) req->file); + SDL_free(req->file); SDL_free(req); } @@ -137,7 +137,7 @@ push_file(const char *serial, const char *file) { bool file_handler_request(struct file_handler *file_handler, file_handler_action_t action, - const char *file) { + char *file) { bool res; // start file_handler if it's used for the first time diff --git a/app/src/file_handler.h b/app/src/file_handler.h index 5d50289d..382477d8 100644 --- a/app/src/file_handler.h +++ b/app/src/file_handler.h @@ -46,9 +46,10 @@ file_handler_stop(struct file_handler *file_handler); void file_handler_join(struct file_handler *file_handler); +// take ownership of file, and will SDL_free() it bool file_handler_request(struct file_handler *file_handler, file_handler_action_t action, - const char *file); + char *file); #endif