sed: fix memory leak in 'r FILE' command
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 30 Oct 2013 09:22:47 +0000 (10:22 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 30 Oct 2013 09:22:47 +0000 (10:22 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c

index ef462843bd4b8bee5c7405d26cd0d655a9b9c8b3..e3cce433ed710667530d452625cf07d13f26bcf8 100644 (file)
@@ -848,7 +848,7 @@ static sed_cmd_t *branch_to(char *label)
 
 static void append(char *s)
 {
-       llist_add_to_end(&G.append_head, xstrdup(s));
+       llist_add_to_end(&G.append_head, s);
 }
 
 static void flush_append(void)
@@ -1181,7 +1181,7 @@ static void process_files(void)
 
                /* Append line to linked list to be printed later */
                case 'a':
-                       append(sed_cmd->string);
+                       append(xstrdup(sed_cmd->string));
                        break;
 
                /* Insert text before this line */
@@ -1203,11 +1203,10 @@ static void process_files(void)
                        rfile = fopen_for_read(sed_cmd->string);
                        if (rfile) {
                                char *line;
-
                                while ((line = xmalloc_fgetline(rfile))
                                                != NULL)
                                        append(line);
-                               xprint_and_close_file(rfile);
+                               fclose(rfile);
                        }
 
                        break;