From 6255f054b7b3304042db4880c1b7d3cb20df0e0e Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 7 Jun 2021 21:00:51 -0400 Subject: Fixed a segfault in `parse_config()`. --- config.c | 10 ++++++++-- 1 file 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; } -- cgit v1.2.3-13-gbd6f