From 35a3c646ed03e5d51c2a2892d201f30b75c66647 Mon Sep 17 00:00:00 2001 From: NightlyFox Date: Wed, 19 Sep 2018 16:43:29 -0500 Subject: [PATCH] added proper deallocation in places of the code for pointers that i allocaded using calloc --- common/menu-entry.c | 3 ++- common/theme.h | 7 +++++++ nx_main/main.c | 23 +---------------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/common/menu-entry.c b/common/menu-entry.c index e8fe006..23fee2f 100644 --- a/common/menu-entry.c +++ b/common/menu-entry.c @@ -137,6 +137,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) { tempbuf[PATH_MAX] = 0; strcpy(me->name, name); + if (me->type == ENTRY_TYPE_FOLDER) { //Check for /.nro @@ -298,7 +299,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) { //Todo load in the data about the theme? //Add a theme name property to each one? //Ability to load the theme as you hover over? - + free((void*)name);//This was allocated by calloc and copied over by strcpy } return true; diff --git a/common/theme.h b/common/theme.h index 5c76d01..187a087 100644 --- a/common/theme.h +++ b/common/theme.h @@ -34,3 +34,10 @@ void themeStartup(ThemePreset preset); theme_t themeCurrent; ThemePreset globalPreset; + + +static inline void themeExit(){ + free((void*)themeCurrent.buttonAText); + free((void*)themeCurrent.buttonBText); +} + \ No newline at end of file diff --git a/nx_main/main.c b/nx_main/main.c index 7dd29a5..3f9404d 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -18,7 +18,6 @@ void audio_initialize(void); void audio_exit(void); #endif -char* getSavedTheme(); int main(int argc, char **argv) { @@ -43,7 +42,6 @@ int main(int argc, char **argv) rc = plInitialize(); if (R_FAILED(rc)) fatalSimple(-6); - //char* savedThemeName = getSavedTheme(); themeStartup((ThemePreset)theme); textInit(); menuStartup(); @@ -101,6 +99,7 @@ int main(int argc, char **argv) #endif fontExit(); + themeExit(); launchExit(); plExit(); setsysExit(); @@ -165,24 +164,4 @@ bool menuUpdate(void) { } return exitflag; -} - - - -char* getSavedTheme(){ - char tmp_path[PATH_MAX]; - #ifdef __SWITCH__ - strcpy(tmp_path,"sdmc:"); - #else - getcwd(tmp_path, PATH_MAX); - #endif - snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s%s%s%s%s", DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes", DIRECTORY_SEPARATOR, "theme.saved"); - FILE* f; - if((f= fopen(tmp_path, "rb"))==NULL) return NULL; //return null if FAILED TO OPEN FILE - char* buffer; - buffer = calloc(1, PATH_MAX+1) ;//calloc already contains zeros - if( 1!=fread(buffer,PATH_MAX, 1, f) ) return NULL;// return null if FAILED TO READ - fclose(f); - return buffer; - } \ No newline at end of file