提交 a41dd6c7 编写于 作者: R Romain Vimont

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.
上级 c3779d85
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
struct request { struct request {
file_handler_action_t action; file_handler_action_t action;
const char *file; char *file;
}; };
static struct request * 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)); struct request *req = SDL_malloc(sizeof(*req));
if (!req) { if (!req) {
return NULL; return NULL;
...@@ -29,7 +29,7 @@ request_free(struct request *req) { ...@@ -29,7 +29,7 @@ request_free(struct request *req) {
if (!req) { if (!req) {
return; return;
} }
SDL_free((void *) req->file); SDL_free(req->file);
SDL_free(req); SDL_free(req);
} }
...@@ -137,7 +137,7 @@ push_file(const char *serial, const char *file) { ...@@ -137,7 +137,7 @@ push_file(const char *serial, const char *file) {
bool bool
file_handler_request(struct file_handler *file_handler, file_handler_request(struct file_handler *file_handler,
file_handler_action_t action, file_handler_action_t action,
const char *file) { char *file) {
bool res; bool res;
// start file_handler if it's used for the first time // start file_handler if it's used for the first time
......
...@@ -46,9 +46,10 @@ file_handler_stop(struct file_handler *file_handler); ...@@ -46,9 +46,10 @@ file_handler_stop(struct file_handler *file_handler);
void void
file_handler_join(struct file_handler *file_handler); file_handler_join(struct file_handler *file_handler);
// take ownership of file, and will SDL_free() it
bool bool
file_handler_request(struct file_handler *file_handler, file_handler_request(struct file_handler *file_handler,
file_handler_action_t action, file_handler_action_t action,
const char *file); char *file);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册