added proper deallocation in places of the code for pointers that i allocaded using calloc

This commit is contained in:
NightlyFox 2018-09-19 16:43:29 -05:00
parent bd239326b0
commit 35a3c646ed
3 changed files with 10 additions and 23 deletions

View File

@ -137,6 +137,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
tempbuf[PATH_MAX] = 0; tempbuf[PATH_MAX] = 0;
strcpy(me->name, name); strcpy(me->name, name);
if (me->type == ENTRY_TYPE_FOLDER) if (me->type == ENTRY_TYPE_FOLDER)
{ {
//Check for <dirpath>/<dirname>.nro //Check for <dirpath>/<dirname>.nro
@ -298,7 +299,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
//Todo load in the data about the theme? //Todo load in the data about the theme?
//Add a theme name property to each one? //Add a theme name property to each one?
//Ability to load the theme as you hover over? //Ability to load the theme as you hover over?
free((void*)name);//This was allocated by calloc and copied over by strcpy
} }
return true; return true;

View File

@ -34,3 +34,10 @@ void themeStartup(ThemePreset preset);
theme_t themeCurrent; theme_t themeCurrent;
ThemePreset globalPreset; ThemePreset globalPreset;
static inline void themeExit(){
free((void*)themeCurrent.buttonAText);
free((void*)themeCurrent.buttonBText);
}

View File

@ -18,7 +18,6 @@ void audio_initialize(void);
void audio_exit(void); void audio_exit(void);
#endif #endif
char* getSavedTheme();
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -43,7 +42,6 @@ int main(int argc, char **argv)
rc = plInitialize(); rc = plInitialize();
if (R_FAILED(rc)) fatalSimple(-6); if (R_FAILED(rc)) fatalSimple(-6);
//char* savedThemeName = getSavedTheme();
themeStartup((ThemePreset)theme); themeStartup((ThemePreset)theme);
textInit(); textInit();
menuStartup(); menuStartup();
@ -101,6 +99,7 @@ int main(int argc, char **argv)
#endif #endif
fontExit(); fontExit();
themeExit();
launchExit(); launchExit();
plExit(); plExit();
setsysExit(); setsysExit();
@ -166,23 +165,3 @@ bool menuUpdate(void) {
return exitflag; 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;
}