]> git.wh0rd.org Git - nano.git/commitdiff
initialize indent_string later in the justify code, so as to avoid a
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 17 Mar 2005 05:08:15 +0000 (05:08 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 17 Mar 2005 05:08:15 +0000 (05:08 +0000)
possible memory leak

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2385 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

src/nano.c

index aa0be72fbdec6dacc18928869bbf0e001b226a64..3a8413fd043984d6f37e2b072a5f86b682d38565 100644 (file)
@@ -2944,7 +2944,7 @@ void do_justify(bool full_justify)
            /* Number of lines in the paragraph we justify. */
        ssize_t break_pos;
            /* Where we will break lines. */
-       char *indent_string = mallocstrcpy(NULL, "");
+       char *indent_string;
            /* The first indentation that doesn't match the initial
             * indentation of the paragraph we justify.  This is put at
             * the beginning of every line broken off the first
@@ -2985,6 +2985,9 @@ void do_justify(bool full_justify)
            first_par_line = backup_lines(current, full_justify ?
                filebot->lineno - current->lineno : par_len, quote_len);
 
+       /* Initialize indent_string to a blank string. */
+       indent_string = mallocstrcpy(NULL, "");
+
        /* Find the first indentation in the paragraph that doesn't
         * match the indentation of the first line, and save it in
         * indent_string.  If all the indentations are the same, save
@@ -3141,7 +3144,6 @@ void do_justify(bool full_justify)
        /* We're done breaking lines, so we don't need indent_string
         * anymore. */
        free(indent_string);
-       indent_string = NULL;
 
        /* Go to the next line, the line after the last line of the
         * paragraph. */