emacs-diffs
[Top][All Lists]
Advanced

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

feature/tree-sitter 7544e9ab5d 2/2: Fix double-free in treesit.c


From: Yuan Fu
Subject: feature/tree-sitter 7544e9ab5d 2/2: Fix double-free in treesit.c
Date: Fri, 17 Jun 2022 20:26:41 -0400 (EDT)

branch: feature/tree-sitter
commit 7544e9ab5d20a773db15ae3538f1c4a3a9167760
Author: Yuan Fu <yuan@debian-BULLSEYE-live-builder-AMD64>
Commit: Yuan Fu <yuan@debian-BULLSEYE-live-builder-AMD64>

    Fix double-free in treesit.c
    
    * src/treesit.c (Ftreesit_query_capture): Remove free at the end.
---
 src/treesit.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/src/treesit.c b/src/treesit.c
index be0955805c..64593898dc 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1706,16 +1706,10 @@ query.  */)
 
   /* Initialize query objects, and execute query.  */
   struct Lisp_TS_Query *lisp_query;
-  /* If the lisp query is temporary, we need to free it after use. */
-  bool lisp_query_temp_p;
   if (TS_COMPILED_QUERY_P (query))
-    {
-      lisp_query_temp_p = false;
       lisp_query = XTS_COMPILED_QUERY (query);
-    }
   else
     {
-      lisp_query_temp_p = true;
       uint32_t error_offset;
       TSQueryError error_type;
       lisp_query = make_ts_query (query, lang,
@@ -1727,6 +1721,8 @@ query.  */)
                    (ts_query_error_to_string (error_type)),
                    make_fixnum (error_offset + 1));
        }
+      /* We don't need need to free TS_QUERY and CURSOR, they are stored
+        in a lisp object, which is tracked by gc.  */
     }
   TSQuery *ts_query = lisp_query->query;
   TSQueryCursor *cursor = lisp_query->cursor;
@@ -1785,11 +1781,6 @@ query.  */)
          result = prev_result;
        }
     }
-  if (lisp_query_temp_p)
-    {
-      ts_query_delete (ts_query);
-      ts_query_cursor_delete (cursor);
-    }
   return Fnreverse (result);
 }
 



reply via email to

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