chiark / gitweb /
fstab-generator: fix minor memory leak on error path
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Mar 2013 17:19:52 +0000 (18:19 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Mar 2013 17:20:03 +0000 (18:20 +0100)
src/fstab-generator/fstab-generator.c

index a0a87a15fce305a85c7b2db884729e7c7263ba4d..7f065eb353f18fbdbbca41b4d07c4e1a7f722eb2 100644 (file)
@@ -468,8 +468,8 @@ finish:
 }
 
 static int parse_new_root_from_proc_cmdline(void) {
-        char *w, *state;
         _cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL;
+        char *w, *state;
         int r;
         size_t l;
 
@@ -487,7 +487,7 @@ static int parse_new_root_from_proc_cmdline(void) {
         /* root= and roofstype= may occur more than once, the last instance should take precedence.
          * In the case of multiple rootflags= the arguments should be concatenated */
         FOREACH_WORD_QUOTED(w, l, line, state) {
-                char *word, *tmp_word;
+                _cleanup_free_ char *word;
 
                 word = strndup(w, l);
                 if (!word)
@@ -506,22 +506,25 @@ static int parse_new_root_from_proc_cmdline(void) {
                                 return log_oom();
 
                 } else if (startswith(word, "rootflags=")) {
-                        tmp_word = opts;
-                        opts = strjoin(opts, ",", word + 10, NULL);
-                        free(tmp_word);
-                        if (!opts)
+                        char *o;
+
+                        o = strjoin(opts, ",", word + 10, NULL);
+                        if (!o)
                                 return log_oom();
 
+                        free(opts);
+                        opts = o;
+
                 } else if (streq(word, "ro") || streq(word, "rw")) {
-                        tmp_word = opts;
-                        opts = strjoin(opts, ",", word, NULL);
-                        free(tmp_word);
-                        if (!opts)
+                        char *o;
+
+                        o = strjoin(opts, ",", word, NULL);
+                        if (!o)
                                 return log_oom();
 
+                        free(opts);
+                        opts = o;
                 }
-
-                free(word);
         }
 
         if (!what) {