fix: config_file_read handle file error before hashmap_new
This commit is contained in:
+10
-4
@@ -68,16 +68,18 @@ void config_file_read(ConfigFile *config, const char *path) {
|
|||||||
char *line;
|
char *line;
|
||||||
char *rest;
|
char *rest;
|
||||||
|
|
||||||
file_read(&file, path);
|
config->map = NULL;
|
||||||
|
|
||||||
config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash,
|
file_read(&file, path);
|
||||||
item_compare, NULL, NULL);
|
|
||||||
|
|
||||||
if (file.error) {
|
if (file.error) {
|
||||||
config->error = true;
|
config->error = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash,
|
||||||
|
item_compare, NULL, NULL);
|
||||||
|
|
||||||
config->error = false;
|
config->error = false;
|
||||||
|
|
||||||
line = strtok_r(file.content, "\n", &rest);
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user