unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* dired.c fails to gc protect lisp object (patch included)
@ 2007-03-11 23:53 Rich Felker
  2007-03-12  4:24 ` Richard Stallman
  0 siblings, 1 reply; 2+ messages in thread
From: Rich Felker @ 2007-03-11 23:53 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

i was experiencing random crashes because file_name_completion (in
dired.c) does not protect the "name" object from garbage collection.
the attached patch seems to fix it.

i'm using emacs-unicode-2 but this might apply to other versions as
well.

~rich felker


[-- Attachment #2: dired-gcpro.diff --]
[-- Type: text/plain, Size: 1141 bytes --]

Index: dired.c
===================================================================
RCS file: /sources/emacs/emacs/src/dired.c,v
retrieving revision 1.104.4.17
diff -u -r1.104.4.17 dired.c
--- dired.c	26 Jan 2007 06:15:08 -0000	1.104.4.17
+++ dired.c	11 Mar 2007 23:39:11 -0000
@@ -521,6 +521,7 @@
   for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
     {
       int inner_count = SPECPDL_INDEX ();
+      struct gcpro gcpro1;
 
       BLOCK_INPUT;
       d = opendir (SDATA (Fdirectory_file_name (encoded_dir)));
@@ -665,6 +666,7 @@
 	    }
 	  else
 	    name = make_string (dp->d_name, len);
+	  GCPRO1(name);
 
 	  /* Test the predicate, if any.  */
 
@@ -673,7 +675,10 @@
 	      Lisp_Object decoded;
 	      decoded = Fexpand_file_name (DECODE_FILE (name), dirname);
 	      if (NILP (call1 (predicate, decoded)))
-		continue;
+		{
+		  UNGCPRO;
+		  continue;
+		}
 	    }
 
 	  /* Suitably record this match.  */
@@ -736,6 +741,7 @@
 		matchsize++;
 	      bestmatchsize = matchsize;
 	    }
+	  UNGCPRO;
 	}
       /* This closes the directory.  */
       bestmatch = unbind_to (inner_count, bestmatch);

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dired.c fails to gc protect lisp object (patch included)
  2007-03-11 23:53 dired.c fails to gc protect lisp object (patch included) Rich Felker
@ 2007-03-12  4:24 ` Richard Stallman
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Stallman @ 2007-03-12  4:24 UTC (permalink / raw)
  To: Rich Felker; +Cc: bug-gnu-emacs

Thanks for finding this bug.  Does this patch fix it?
I like it better because it is more local.

Index: dired.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/dired.c,v
retrieving revision 1.130
diff -c -c -r1.130 dired.c
*** dired.c	13 Jan 2007 21:45:34 -0000	1.130
--- dired.c	12 Mar 2007 03:24:31 -0000
***************
*** 670,677 ****
  	  if (!NILP (predicate))
  	    {
  	      Lisp_Object decoded;
  	      decoded = Fexpand_file_name (DECODE_FILE (name), dirname);
! 	      if (NILP (call1 (predicate, decoded)))
  		continue;
  	    }
  
--- 670,684 ----
  	  if (!NILP (predicate))
  	    {
  	      Lisp_Object decoded;
+ 	      Lisp_Object val;
+ 	      struct gcpro gcpro1;
+ 
+ 	      GCPRO1 (name);
  	      decoded = Fexpand_file_name (DECODE_FILE (name), dirname);
! 	      val = call1 (predicate, decoded);
! 	      UNGCPRO;
! 
! 	      if (NILP (val))
  		continue;
  	    }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-12  4:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-11 23:53 dired.c fails to gc protect lisp object (patch included) Rich Felker
2007-03-12  4:24 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).