diff --git a/src/file.c b/src/file.c index c68c5fc..165bc9f 100644 --- a/src/file.c +++ b/src/file.c @@ -131,7 +131,7 @@ void file_write(const char *path, const StringArray *lines) { } void file_free(File *file) { - if (!file->error) { + if (!file->error && file->content != NULL) { free(file->content); } } diff --git a/src/project.c b/src/project.c index 91961b1..4eda19a 100644 --- a/src/project.c +++ b/src/project.c @@ -104,6 +104,12 @@ void project_init(Project *project, const char *project_path, project->sub_counts.length = project->frag_count; + for (unsigned int i = 0; i < project->frag_count; i++) { + for (unsigned int j = 0; j < MAX_SUB_FILE + 1; j++) { + project->fragment_shaders[i][j].content = NULL; + } + } + for (unsigned int i = 0; i < project->frag_count; i++) { project->sub_counts.values[i] = 0; if (!read_fragment_shader_file(project, frag_prefix, i)) { @@ -138,7 +144,9 @@ void project_reload(Project *project, void (*reload_callback)(unsigned int)) { void project_free(Project *project) { for (unsigned int i = 0; i < project->frag_count; i++) { - file_free(&project->fragment_shaders[i][0]); + for (unsigned int j = 0; j < MAX_SUB_FILE + 1; j++) { + file_free(&project->fragment_shaders[i][j]); + } } config_file_free(&project->config);