emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c0bb1aac10: Fix reader memory leak upon error (bug#56623)


From: Mattias Engdegård
Subject: master c0bb1aac10: Fix reader memory leak upon error (bug#56623)
Date: Mon, 29 Aug 2022 11:50:29 -0400 (EDT)

branch: master
commit c0bb1aac102f8727484763370b154f635a6a1fd1
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Fix reader memory leak upon error (bug#56623)
    
    Reported by Tom Gillespie; error found by Greg Hendershott.
    
    * src/lread.c (read_stack_reset): New.
    (read0): Reset read stack when unwinding from an error.
---
 src/lread.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/lread.c b/src/lread.c
index ccccd79cd7..15bbf46f78 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3686,6 +3686,12 @@ read_stack_push (struct read_stack_entry e)
   rdstack.stack[rdstack.sp++] = e;
 }
 
+static void
+read_stack_reset (intmax_t sp)
+{
+  eassert (sp <= rdstack.sp);
+  rdstack.sp = sp;
+}
 
 /* Read a Lisp object.
    If LOCATE_SYMS is true, symbols are read with position.  */
@@ -3699,6 +3705,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
   specpdl_ref count = SPECPDL_INDEX ();
 
   ptrdiff_t base_sp = rdstack.sp;
+  record_unwind_protect_intmax (read_stack_reset, base_sp);
 
   bool uninterned_symbol;
   bool skip_shorthand;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]