From 8484a868194482b2c4b31bb22fe0b31ea08d1403 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 1 Mar 2018 18:59:41 +0300 Subject: [PATCH] Crash when copying and pasting in several editors (sprite, map editor) #558 --- .gitignore | 2 ++ src/code.c | 2 +- src/map.c | 2 +- src/music.c | 2 +- src/studio.c | 2 +- src/system.c | 7 +++++++ src/system.h | 2 ++ src/system/chip.c | 7 +++++++ 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ad5ae32..ae712b5 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,5 @@ build/uwp/sdl-gpu-static/Release Pro/ build/uwp/sdl-gpu-static/ARM/ build/uwp/sdl-gpu-static/x64/ build/uwp/tic/packages/ +build/windows/studio/x64/ +build/windows/sdl-gpu/x64/ diff --git a/src/code.c b/src/code.c index de97b6c..47daef3 100644 --- a/src/code.c +++ b/src/code.c @@ -590,7 +590,7 @@ static void copyFromClipboard(Code* code) parseSyntaxColor(code); } - free(clipboard); + getSystem()->freeClipboardText(clipboard); } } } diff --git a/src/map.c b/src/map.c index 6fee908..b82a89f 100644 --- a/src/map.c +++ b/src/map.c @@ -1004,7 +1004,7 @@ static void copyFromClipboard(Map* map) else free(data); } - free(clipboard); + getSystem()->freeClipboardText(clipboard); } } } diff --git a/src/music.c b/src/music.c index 738b00f..ff75e69 100644 --- a/src/music.c +++ b/src/music.c @@ -651,7 +651,7 @@ static void copyFromClipboard(Music* music) free(data); } - free(clipboard); + getSystem()->freeClipboardText(clipboard); } } } diff --git a/src/studio.c b/src/studio.c index 1d00666..e845e83 100644 --- a/src/studio.c +++ b/src/studio.c @@ -417,7 +417,7 @@ bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces) if(valid) str2buf(clipboard, strlen(clipboard), data, flip); - free(clipboard); + getSystem()->freeClipboardText(clipboard); return valid; } diff --git a/src/system.c b/src/system.c index af49d0c..e19d11c 100644 --- a/src/system.c +++ b/src/system.c @@ -876,6 +876,11 @@ static char* getClipboardText() return SDL_GetClipboardText(); } +static void freeClipboardText(const char* text) +{ + SDL_free((void*)text); +} + static u64 getPerformanceCounter() { return SDL_GetPerformanceCounter(); @@ -1057,6 +1062,8 @@ static System systemInterface = .setClipboardText = setClipboardText, .hasClipboardText = hasClipboardText, .getClipboardText = getClipboardText, + .freeClipboardText = freeClipboardText, + .getPerformanceCounter = getPerformanceCounter, .getPerformanceFrequency = getPerformanceFrequency, diff --git a/src/system.h b/src/system.h index c08768d..1e09e10 100644 --- a/src/system.h +++ b/src/system.h @@ -8,6 +8,8 @@ typedef struct void (*setClipboardText)(const char* text); bool (*hasClipboardText)(); char* (*getClipboardText)(); + void (*freeClipboardText)(const char* text); + u64 (*getPerformanceCounter)(); u64 (*getPerformanceFrequency)(); diff --git a/src/system/chip.c b/src/system/chip.c index cc4f30f..6755a82 100644 --- a/src/system/chip.c +++ b/src/system/chip.c @@ -517,6 +517,11 @@ static char* getClipboardText() return SDL_GetClipboardText(); } +static void freeClipboardText(const char* text) +{ + SDL_free((void*)text); +} + static u64 getPerformanceCounter() { return SDL_GetPerformanceCounter(); @@ -599,6 +604,8 @@ static System systemInterface = .setClipboardText = setClipboardText, .hasClipboardText = hasClipboardText, .getClipboardText = getClipboardText, + .freeClipboardText = freeClipboardText, + .getPerformanceCounter = getPerformanceCounter, .getPerformanceFrequency = getPerformanceFrequency,