diff options
author | Benny Baumann <BenBE@geshi.org> | 2024-04-15 09:43:20 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2024-04-16 23:53:58 +0200 |
commit | eaeeda64c12ee7d16bfbb591a0ca2d1a4809ebb7 (patch) | |
tree | 47a090ca7968b704bbf5035d9d05be792320d249 | |
parent | 8122fc394e05507c514425b1f96637668dcefe65 (diff) |
Memory leak when a legacy config file exists
Fixes regression caused by 15b4bc45b2b0ccf2
Fixes: #1449
Co-authored-by: Kang-Che Sung <explorer09@gmail.com>
-rw-r--r-- | Settings.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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; } |