From 8119235833dc0861c34086f639a60546cda2739c Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Thu, 17 Jun 2010 22:44:23 +0200 Subject: [PATCH] fix bad free when reading the configuration file We change the initial pointer when parsing the line, the address we are trying to free is modified in case there are blanks before an option. Signed-off-by: Daniel Lezcano --- src/lxc/confile.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 06f4b2c0b..127fb3700 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -718,7 +718,7 @@ static int config_utsname(const char *key, char *value, struct lxc_conf *lxc_con static int parse_line(char *buffer, void *data) { struct config *config; - char *line; + char *line, *linep; char *dot; char *key; char *value; @@ -727,13 +727,14 @@ static int parse_line(char *buffer, void *data) if (lxc_is_line_empty(buffer)) return 0; - /* we have to dup the buffer otherwise, at the re-exec for reboot we modified - * the original string on the stack by replacing '=' by '\0' below + /* we have to dup the buffer otherwise, at the re-exec for + * reboot we modified the original string on the stack by + * replacing '=' by '\0' below */ - line = strdup(buffer); + linep = line = strdup(buffer); if (!line) { SYSERROR("failed to allocate memory for '%s'", buffer); - goto out; + return -1; } line += lxc_char_left_gc(line, strlen(line)); @@ -766,7 +767,7 @@ static int parse_line(char *buffer, void *data) ret = config->cb(key, value, data); out: - free(line); + free(linep); return ret; } -- 2.47.2