From 3bc1c51b91dbad1e67bb93371599049217508890 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 30 May 2019 00:10:45 +0200 Subject: [PATCH] Always use SDL_malloc() and SDL_free() To avoid mixing SDL_malloc()/SDL_strdup() with free(), or malloc() with SDL_free(), always use the SDL version. --- app/src/command.c | 8 ++++---- app/src/str_util.c | 6 ++++-- app/src/stream.c | 4 ++-- app/src/sys/win/command.c | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/command.c b/app/src/command.c index 2c6d45aa..717455dd 100644 --- a/app/src/command.c +++ b/app/src/command.c @@ -147,7 +147,7 @@ adb_push(const char *serial, const char *local, const char *remote) { } remote = strquote(remote); if (!remote) { - free((void *) local); + SDL_free((void *) local); return PROCESS_NONE; } #endif @@ -156,8 +156,8 @@ adb_push(const char *serial, const char *local, const char *remote) { process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd)); #ifdef __WINDOWS__ - free((void *) remote); - free((void *) local); + SDL_free((void *) remote); + SDL_free((void *) local); #endif return proc; @@ -178,7 +178,7 @@ adb_install(const char *serial, const char *local) { process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd)); #ifdef __WINDOWS__ - free((void *) local); + SDL_free((void *) local); #endif return proc; diff --git a/app/src/str_util.c b/app/src/str_util.c index 3509331a..d9ae6948 100644 --- a/app/src/str_util.c +++ b/app/src/str_util.c @@ -8,6 +8,8 @@ # include #endif +#include + size_t xstrncpy(char *dest, const char *src, size_t n) { size_t i; @@ -45,7 +47,7 @@ truncated: char * strquote(const char *src) { size_t len = strlen(src); - char *quoted = malloc(len + 3); + char *quoted = SDL_malloc(len + 3); if (!quoted) { return NULL; } @@ -65,7 +67,7 @@ utf8_to_wide_char(const char *utf8) { return NULL; } - wchar_t *wide = malloc(len * sizeof(wchar_t)); + wchar_t *wide = SDL_malloc(len * sizeof(wchar_t)); if (!wide) { return NULL; } diff --git a/app/src/stream.c b/app/src/stream.c index 7ed95ee8..0e751eb3 100644 --- a/app/src/stream.c +++ b/app/src/stream.c @@ -24,7 +24,7 @@ static struct frame_meta * frame_meta_new(uint64_t pts) { - struct frame_meta *meta = malloc(sizeof(*meta)); + struct frame_meta *meta = SDL_malloc(sizeof(*meta)); if (!meta) { return meta; } @@ -35,7 +35,7 @@ frame_meta_new(uint64_t pts) { static void frame_meta_delete(struct frame_meta *frame_meta) { - free(frame_meta); + SDL_free(frame_meta); } static bool diff --git a/app/src/sys/win/command.c b/app/src/sys/win/command.c index 1cd7274f..8434dc98 100644 --- a/app/src/sys/win/command.c +++ b/app/src/sys/win/command.c @@ -44,7 +44,7 @@ cmd_execute(const char *path, const char *const argv[], HANDLE *handle) { #endif if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, flags, NULL, NULL, &si, &pi)) { - free(wide); + SDL_free(wide); *handle = NULL; if (GetLastError() == ERROR_FILE_NOT_FOUND) { return PROCESS_ERROR_MISSING_BINARY; @@ -52,7 +52,7 @@ cmd_execute(const char *path, const char *const argv[], HANDLE *handle) { return PROCESS_ERROR_GENERIC; } - free(wide); + SDL_free(wide); *handle = pi.hProcess; return PROCESS_SUCCESS; }