Fix a few memory leaks and out of bounds buffer access

This commit is contained in:
Joel16 2020-05-13 13:55:31 -04:00
parent 04d9792918
commit 707c30650e
3 changed files with 9 additions and 3 deletions

View File

@ -81,11 +81,13 @@ int Config_Load(void) {
jsmn_init(&parser);
if (R_FAILED(ret = jsmn_parse(&parser, buf, strlen(buf), token, 128))) {
Log_Print("jsmn_parse failed in Config_Load %d\n", ret);
free(buf);
return ret;
}
if (ret < 1 || token[0].type != JSMN_OBJECT) {
Log_Print("jsmn_parse failed: object expected\n");
free(buf);
return ret;
}

View File

@ -84,7 +84,7 @@ int Archive_ExtractArchive(const char *path) {
char *dest_path = (char *)calloc(256, sizeof(char));
char *dirname_without_ext = Archive_RemoveFileExt((char *)path);
snprintf(dest_path, 512, "%s/", dirname_without_ext);
snprintf(dest_path, 256, "%s/", dirname_without_ext);
FS_MakeDir(dest_path);
int count = 0;

View File

@ -50,8 +50,10 @@ static int FileOptions_CreateFolder(void) {
char *buf = malloc(256);
strcpy(buf, G2D_KeyboardGetText("Enter name", "New folder"));
if (strncmp(buf, "", 1) == 0)
if (strncmp(buf, "", 1) == 0) {
free(buf);
return -1;
}
char path[512];
strcpy(path, cwd);
@ -70,8 +72,10 @@ static int FileOptions_CreateFile(void) {
char *buf = malloc(256);
strcpy(buf, G2D_KeyboardGetText("Enter name", "New file"));
if (strncmp(buf, "", 1) == 0)
if (strncmp(buf, "", 1) == 0) {
free(buf);
return -1;
}
char path[512];
strcpy(path, cwd);