Vim7 crash with multiple substitutes and global commands

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Vim7 crash with multiple substitutes and global commands

Dave Roberts
Hello all,

(WinXP, latest VIM7 from cvs sources but has been happening for a while)

I'm creating a script to convert html to text that it's in a form
similar to Mikolaj Machowsk's VST text.

What I'm seeing is that if I run the script then vim is unstable and
will eventually crash. If I 'undo' and then run it again it crashed
immediately.

It seems to be a cumulative thing. If I remove some of the substitutes
it takes longer to crash but eventually does.

I got it down to two lines by running a script that just runs the
substitute script then does an undo for either 1000 times or until it
crashes.

How to recreate:

- Create htmltodst.vim containing:
g;\c<head;.,/\c<\/head/d
%s;\c<br[^>]*>;\r;ge

- Take any (not small) HTML page (I grabbed the main page from
slashdot.org) and load it into VIM.

- Run gvim -u NONE -U NONE slashdot.org.htm (or whatever HTML file you use)

- At the command line run (cut and paste from here):
let cnt=1|while cnt < 1000|so htmltodst.vim|exe "normal u"|let
cnt=cnt+1|endwhile

After it blows up don't forget to remove the swap file in the current
directory.

Thanks,

- Dave


Reply | Threaded
Open this post in threaded view
|

Re: Vim7 crash with multiple substitutes and global commands

Bram Moolenaar

Dave Roberts wrote:

> (WinXP, latest VIM7 from cvs sources but has been happening for a while)
>
> I'm creating a script to convert html to text that it's in a form
> similar to Mikolaj Machowsk's VST text.
>
> What I'm seeing is that if I run the script then vim is unstable and
> will eventually crash. If I 'undo' and then run it again it crashed
> immediately.
>
> It seems to be a cumulative thing. If I remove some of the substitutes
> it takes longer to crash but eventually does.
>
> I got it down to two lines by running a script that just runs the
> substitute script then does an undo for either 1000 times or until it
> crashes.
>
> How to recreate:
>
> - Create htmltodst.vim containing:
> g;\c<head;.,/\c<\/head/d
> %s;\c<br[^>]*>;\r;ge
>
> - Take any (not small) HTML page (I grabbed the main page from
> slashdot.org) and load it into VIM.
>
> - Run gvim -u NONE -U NONE slashdot.org.htm (or whatever HTML file you use)
>
> - At the command line run (cut and paste from here):
> let cnt=1|while cnt < 1000|so /tmp/test.vim|exe "normal u"|let cnt=cnt+1|endwhile
>
> After it blows up don't forget to remove the swap file in the current
> directory.

Thanks for the reproducable example.  It still took quite a bit of
debugging to pin down the problem but I found it: A pointer was freed
that wasn't pointing to allocated memory.  Side effect of cleaning up a
memory leak.

This patch will fix it:

Index: undo.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/undo.c,v
retrieving revision 1.8
diff -u -r1.8 undo.c
--- undo.c 9 Jul 2005 21:07:08 -0000 1.8
+++ undo.c 12 Jul 2005 20:25:17 -0000
@@ -656,6 +656,8 @@
  ml_delete(lnum, FALSE);
     }
  }
+ else
+    newarray = NULL;
 
  /* insert the lines in u_array between top and bot */
  if (newsize)

--
        **  Hello and Welcome to the Psychiatric Hotline **
If you are obsessive-compulsive, please press 1 repeatedly.
If you are co-dependent, please ask someone to press 2.
If you have multiple personalities, please press 3, 4, 5 and 6.
If you are paranoid-delusional, we know who you are and what you want
       - just stay on the line so we can trace the call.
If you are schizophrenic, listen carefully and a little voice will
       tell you which number to press next.
If you are manic-depressive, it doesn't matter which number you press
       - no one will answer.
If you suffer from panic attacks, push every button you can find.
If you are sane, please hold on - we have the rest of humanity on the
        other line and they desparately want to ask you a few questions.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: Vim7 crash with multiple substitutes and global commands

Dave Roberts
Bram Moolenaar wrote:

>Thanks for the reproducable example.  It still took quite a bit of
>debugging to pin down the problem but I found it: A pointer was freed
>that wasn't pointing to allocated memory.  Side effect of cleaning up a
>memory leak.
>
>This patch will fix it:
>
>Index: undo.c
>===================================================================
>RCS file: /cvsroot/vim/vim7/src/undo.c,v
>retrieving revision 1.8
>diff -u -r1.8 undo.c
>--- undo.c 9 Jul 2005 21:07:08 -0000 1.8
>+++ undo.c 12 Jul 2005 20:25:17 -0000
>@@ -656,6 +656,8 @@
> ml_delete(lnum, FALSE);
>    }
> }
>+ else
>+    newarray = NULL;
>
> /* insert the lines in u_array between top and bot */
> if (newsize)
>
>  
>

Looks like that did it. I ran the full script against the same HTML file
over and over again and it's still running fine.

Thanks,

- Dave