From e6b7905fe6510a31893ca14383fd2cafafbc8e2f Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Sun, 21 Feb 2021 17:29:52 +0100 Subject: Fix memory leak when loading previous preferences from splash screen When opening a Blender version for which there are no preferences, the splash shows a button like "Load 2.92 Settings". Using this could cause a memory leak of the storage for recently opened files. --- source/blender/windowmanager/intern/wm_files.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 090c28a81a6..8bea2203abe 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -140,6 +140,7 @@ static RecentFile *wm_file_history_find(const char *filepath); static void wm_history_file_free(RecentFile *recent); +static void wm_history_files_free(void); static void wm_history_file_update(void); static void wm_history_file_write(void); @@ -1188,7 +1189,7 @@ void wm_history_file_read(void) lines = BLI_file_read_as_lines(name); - BLI_listbase_clear(&G.recent_files); + wm_history_files_free(); /* read list of recent opened files from recent-files.txt to memory */ for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) { @@ -1219,6 +1220,13 @@ static void wm_history_file_free(RecentFile *recent) BLI_freelinkN(&G.recent_files, recent); } +static void wm_history_files_free(void) +{ + LISTBASE_FOREACH_MUTABLE (RecentFile *, recent, &G.recent_files) { + wm_history_file_free(recent); + } +} + static RecentFile *wm_file_history_find(const char *filepath) { return BLI_findstring_ptr(&G.recent_files, filepath, offsetof(RecentFile, filepath)); -- cgit v1.2.3