Hi Bram!

On Di, 18 Dez 2012, Bram Moolenaar wrote:

> 
> Christian Brabandt wrote:
> 
> > On Mo, 17 Dez 2012, Sean Reifschneider wrote:
> > 
> > > Since vim 7.3 patch 429 (on Ubuntu Precise/12.04), it looks like there's 
> > > a segfault issue when doing "cclose" on BufUnload in a python function.  
> > > In particular, it happens on 7.3 patch 547 (Ubuntu Quantal/12.10), and is 
> > > also happening on 7.3 patch 762 (latest tag in Mercurial checkout).
> > > 
> > > Here's how I'm able to reproduce it:
> > > 
> > > Create a file /tmp/blowup.vim:
> > > 
> > >    pyfile /tmp/blowup.py
> > >    botright 3copen
> > >    autocmd BufUnload * python leaving_buffer()
> > > 
> > > Then create a file /tmp/blowup.py:
> > > 
> > >    import vim
> > >    def leaving_buffer():
> > >            vim.command('cclose')
> > >            vim.command('quit')
> > > 
> > > Now run "vim -u tmp/blowup.vim /tmp/foo" (in my case, /tmp/foo does not 
> > > exist).   Do ":q" in vim, and it will segfault:
> > > 
> > > Vim: Caught deadly signal SEGV
> > > zsh: segmentation fault (core dumped)  vim -u /tmp/blowup.vim /tmp/foo
> > > 
> > 
> > This is an issue, that seems to come up in one or another form every 
> > couple of months here. The root cause is always autocommands closing all 
> > windows and buffers, which Vim does not expect and so it crashes sooner 
> > or later. Here is a patch, trying to prevent this another time:
> 
> Thanks Christian, added to the todo list.
> Note that I am travelling, expect some delay.
> 
> 
> > This does quit Vim, in case an autocommand closes all other 
> > windows/buffers while Vim is processing the win_close() function. 
> 
> What if there are unsaved changes?

Here is a small updated patch. unsaved changes shouldn't be a problem in 
this case, since we are explicitly checking that the buffer is null.


regards,
Christian
-- 
Man ist nur vielseitig, wenn man zum Höchsten strebt, weil man 
muss (im Ernst), und zum Geringern herabsteigt, wenn man will (zum 
Spaß).
                -- Goethe, Maximen und Reflektionen, Nr. 1157

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -1376,6 +1376,8 @@
 	    for (wp = (tp == curtab)
 		    ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next)
 	    {
+		if (wp->w_buffer == NULL)
+		    continue;
 		buf = wp->w_buffer;
 		if (buf->b_changedtick != -1)
 		{
diff --git a/src/window.c b/src/window.c
--- a/src/window.c
+++ b/src/window.c
@@ -2276,9 +2276,14 @@
 #endif
     }
 
+    if (only_one_window() && win->w_buffer == NULL &&
+	(!win_valid(win) || last_window() || curtab != prev_curtab
+	|| close_last_window_tabpage(win, free_buf, prev_curtab)))
+	/* autocommands have close all windows, quit now */
+	getout(0);
     /* Autocommands may have closed the window already, or closed the only
      * other window or moved to another tab page. */
-    if (!win_valid(win) || last_window() || curtab != prev_curtab
+    else if (!win_valid(win) || last_window() || curtab != prev_curtab
 	    || close_last_window_tabpage(win, free_buf, prev_curtab))
 	return;
 
@@ -6281,7 +6286,7 @@
     if (first_tabpage->tp_next != NULL)
 	return FALSE;
 
-    for (wp = firstwin; wp != NULL; wp = wp->w_next)
+    for (wp = firstwin; wp != NULL && wp->w_buffer != NULL; wp = wp->w_next)
 	if ((!((wp->w_buffer->b_help && !curbuf->b_help)
 # ifdef FEAT_QUICKFIX
 		    || wp->w_p_pvw

Raspunde prin e-mail lui