]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix bad free when reading the configuration file
authorDaniel Lezcano <daniel.lezcano@free.fr>
Thu, 17 Jun 2010 20:44:23 +0000 (22:44 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 17 Jun 2010 20:44:23 +0000 (22:44 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/confile.c

index 06f4b2c0bc356b39b4ccc275d37fcbdfd2b3adce..127fb3700534ef5430f347c649881b81b5690e57 100644 (file)
@@ -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;
 }