Subject: Re: bug#16502: segmentation fault with org-capture

From: Dmitry Antipov <[email-masked]>
Date: Mon, 20 Jan 2014 13:30:47 +0400

On 01/20/2014 12:20 PM, Dmitry Antipov wrote:

> Could you please run undumped (temacs) under valgrind?

...and please try this patch (for trunk), if possible.

Dmitry

=== modified file 'src/buffer.c'
--- src/buffer.c	2014-01-01 07:43:34 +0000
+++ src/buffer.c	2014-01-20 09:22:59 +0000
@@ -1867,6 +1867,7 @@
 
   if (b->base_buffer)
     {
+      INTERVAL i;
       /* Unchain all markers that belong to this indirect buffer.
 	 Don't unchain the markers that belong to the base buffer
 	 or its other indirect buffers.  */
@@ -1881,6 +1882,14 @@
 	  else
 	    mp = &m->next;
 	}
+      /* Intervals should be owned by the base buffer (Bug#16502).  */
+      i = buffer_intervals (b);
+      if (i)
+	{
+	  Lisp_Object owner;
+	  XSETBUFFER (owner, b->base_buffer);
+	  set_interval_object (i, owner);
+	}
     }
   else
     {

=== modified file 'src/intervals.c'
--- src/intervals.c	2014-01-01 07:43:34 +0000
+++ src/intervals.c	2014-01-20 09:21:55 +0000
@@ -60,16 +60,7 @@
 
 /* Utility functions for intervals.  */
 
-/* Use these functions to set Lisp_Object
-   or pointer slots of struct interval.  */
-
-static void
-set_interval_object (INTERVAL i, Lisp_Object obj)
-{
-  eassert (BUFFERP (obj) || STRINGP (obj));
-  i->up_obj = 1;
-  i->up.obj = obj;
-}
+/* Use these functions to set pointer slots of struct interval.  */
 
 static void
 set_interval_left (INTERVAL i, INTERVAL left)

=== modified file 'src/intervals.h'
--- src/intervals.h	2014-01-01 07:43:34 +0000
+++ src/intervals.h	2014-01-20 09:22:10 +0000
@@ -134,6 +134,14 @@
    or pointer slots of struct interval.  */
 
 INLINE void
+set_interval_object (INTERVAL i, Lisp_Object obj)
+{
+  eassert (BUFFERP (obj) || STRINGP (obj));
+  i->up_obj = 1;
+  i->up.obj = obj;
+}
+
+INLINE void
 set_interval_parent (INTERVAL i, INTERVAL parent)
 {
   i->up_obj = false;