Memory leak when a legacy config file exists

Fixes regression caused by 15b4bc45b2

Fixes: #1449
Co-authored-by: Kang-Che Sung <explorer09@gmail.com>
wilder
Benny Baumann 2 years ago committed by BenBE
parent 8122fc394e
commit eaeeda64c1
  1. 7
      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;
}

Loading…
Cancel
Save