[Fix] Mem leak: What if there is no files to load in load menu?

This commit is contained in:
Allanis 2013-05-15 21:57:37 +01:00
parent 538b4b20eb
commit c1058cb7a5
2 changed files with 16 additions and 0 deletions

View File

@ -91,6 +91,12 @@ char** lfile_readDir(int* lfiles, char* path) {
closedir(d);
#endif
// What if we find nothing?
if((*lfiles) = 0) {
free(files);
files = NULL;
}
return files;
}

View File

@ -106,6 +106,13 @@ void load_game_menu(void) {
files[i][len-3] = '\0';
}
// Again.. What if there is no files?
if(files == NULL) {
files = malloc(sizeof(char*));
files[0] = strdup("None");
lfiles = 1;
}
window_addList(wid, 20, -50,
LOAD_WIDTH-BUTTON_WIDTH-50, LOAD_HEIGHT-90,
"lstSaves", files, lfiles, 0, NULL);
@ -136,6 +143,9 @@ static void load_menu_load(char* str) {
save = toolkit_getList(wid, "lstSaves");
if(strcmp(save, "None")==0)
return;
snprintf(path, PATH_MAX, "%ssaves/%s.ls", lfile_basePath(), save);
load_game(path);
load_menu_close(NULL);