diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-07 21:00:51 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-07 21:00:51 -0400 |
commit | 6255f054b7b3304042db4880c1b7d3cb20df0e0e (patch) | |
tree | 529b2c5dfd796c177db6d84cda2d8826058526e7 /config.c | |
parent | 9863a2dba4eec9c3d18ef2008601728e04be4f77 (diff) |
Fixed a segfault in `parse_config()`.
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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; } |