fix: config_file_read handle file error before hashmap_new

This commit is contained in:
2026-05-16 17:54:05 +02:00
parent a92cca33ad
commit 988cf799b4
+10 -4
View File
@@ -68,16 +68,18 @@ void config_file_read(ConfigFile *config, const char *path) {
char *line;
char *rest;
file_read(&file, path);
config->map = NULL;
config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash,
item_compare, NULL, NULL);
file_read(&file, path);
if (file.error) {
config->error = true;
return;
}
config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash,
item_compare, NULL, NULL);
config->error = false;
line = strtok_r(file.content, "\n", &rest);
@@ -138,4 +140,8 @@ unsigned int config_file_get_int(const ConfigFile *config, const char *key,
return (unsigned int)atoi(item->value);
}
void config_file_free(const ConfigFile *config) { hashmap_free(config->map); }
void config_file_free(const ConfigFile *config) {
if (config->map != NULL) {
hashmap_free(config->map);
}
}