From eaeeda64c12ee7d16bfbb591a0ca2d1a4809ebb7 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 15 Apr 2024 09:43:20 +0200 Subject: Memory leak when a legacy config file exists Fixes regression caused by 15b4bc45b2b0ccf2 Fixes: #1449 Co-authored-by: Kang-Che Sung --- Settings.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Settings.c b/Settings.c index e2c94e2b..86757dc9 100644 --- a/Settings.c +++ b/Settings.c @@ -815,12 +815,13 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H configDir = String_cat(home, "/.config"); htopDir = String_cat(home, "/.config/htop"); } - legacyDotfile = String_cat(home, "/.htoprc"); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); free(htopDir); free(configDir); + struct stat st; + legacyDotfile = String_cat(home, "/.htoprc"); int err = lstat(legacyDotfile, &st); if (err || S_ISLNK(st.st_mode)) { free(legacyDotfile); @@ -838,6 +839,7 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H #endif this->changed = false; this->delay = DEFAULT_DELAY; + bool ok = Settings_read(this, this->filename, initialCpuCount); if (!ok && legacyDotfile) { ok = Settings_read(this, legacyDotfile, initialCpuCount); @@ -847,7 +849,6 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H unlink(legacyDotfile); } } - free(legacyDotfile); } if (!ok) { this->screenTabs = true; @@ -864,6 +865,8 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H this->lastUpdate = 1; + free(legacyDotfile); + return this; } -- cgit v1.2.3