summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2021-10-06 00:00:13 +0200
committerBenBE <BenBE@geshi.org>2021-10-06 08:59:02 +0200
commit2a13e15ad0e32447fc683b54f39e9ab5f6c7f6f4 (patch)
tree83e4d48d5e274b9a86b15f464e36d96b70a1ca3f
parent8ac8542b6e710fde88aa444f8379a4ddfdfce6d3 (diff)
Properly release memory on partially read configuration
-rw-r--r--Settings.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Settings.c b/Settings.c
index e4b0aad9..9b545a19 100644
--- a/Settings.c
+++ b/Settings.c
@@ -28,11 +28,7 @@ void Settings_delete(Settings* this) {
free(this->filename);
free(this->fields);
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
- if (this->hColumns[i].names) {
- for (size_t j = 0; j < this->hColumns[i].len; j++)
- free(this->hColumns[i].names[j]);
- free(this->hColumns[i].names);
- }
+ String_freeArray(this->hColumns[i].names);
free(this->hColumns[i].modes);
}
free(this->hColumns);
@@ -67,14 +63,26 @@ static void Settings_readMeterModes(Settings* this, const char* line, unsigned i
static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) {
int sizes[] = { 3, 3 };
+
if (initialCpuCount > 4 && initialCpuCount <= 128) {
sizes[1]++;
}
- for (int i = 0; i < 2; i++) {
+
+ // Release any previously allocated memory
+ for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
+ String_freeArray(this->hColumns[i].names);
+ free(this->hColumns[i].modes);
+ }
+ free(this->hColumns);
+
+ this->hLayout = HF_TWO_50_50;
+ this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
+ for (size_t i = 0; i < 2; i++) {
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(int));
this->hColumns[i].len = sizes[i];
}
+
int r = 0;
if (initialCpuCount > 128) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy