summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-07 21:00:51 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-07 21:00:51 -0400
commit6255f054b7b3304042db4880c1b7d3cb20df0e0e (patch)
tree529b2c5dfd796c177db6d84cda2d8826058526e7 /config.c
parent9863a2dba4eec9c3d18ef2008601728e04be4f77 (diff)
Fixed a segfault in `parse_config()`.
Diffstat (limited to 'config.c')
-rw-r--r--config.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/config.c b/config.c
index 2874e89..5435eb9 100644
--- a/config.c
+++ b/config.c
@@ -104,6 +104,7 @@ config *parse_config(const char *filename) {
config *cfg;
/* Buffer of the file contents. */
char *buf = read_file(filename, &filesize);
+ char *tmp = buf;
/* Return NULL, if the buffer wasn't allocated */
if (buf == NULL) {
@@ -118,8 +119,8 @@ config *parse_config(const char *filename) {
return NULL;
}
- while (*buf != '\0') {
- char *line = get_line(&buf);
+ while (*tmp != '\0') {
+ char *line = get_line(&tmp);
char *value;
char *name = strtok_r(line, "=", &value);
const config_opt *opt;
@@ -132,5 +133,10 @@ config *parse_config(const char *filename) {
config_val val = parse_option_value(opt, value);
set_config_opt(cfg, opt->type, opt->offset, val);
}
+
+ free(line);
}
+
+ free(buf);
+ return cfg;
}