emacs-diffs
[Top][All Lists]
Advanced

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

scratch/igc e8deac66ade 2/2: Attempt to catch mismatched igc_xzalloc/xfr


From: Pip Cet
Subject: scratch/igc e8deac66ade 2/2: Attempt to catch mismatched igc_xzalloc/xfree calls
Date: Fri, 10 Jan 2025 11:22:09 -0500 (EST)

branch: scratch/igc
commit e8deac66adef279a15c806d7547a7610b0189795
Author: Pip Cet <pipcet@protonmail.com>
Commit: Pip Cet <pipcet@protonmail.com>

    Attempt to catch mismatched igc_xzalloc/xfree calls
    
    * src/igc.h:
    * src/igc.c (igc_check_freeable) [ENABLE_CHECKING]: New function.
    * src/alloc.c (xfree): Call it.
---
 src/alloc.c |  3 +++
 src/igc.c   | 14 ++++++++++++++
 src/igc.h   |  3 +++
 3 files changed, 20 insertions(+)

diff --git a/src/alloc.c b/src/alloc.c
index 0c7036e0d61..ffbde54b38e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -843,6 +843,9 @@ xfree (void *block)
     return;
   if (pdumper_object_p (block))
     return;
+#if defined (ENABLE_CHECKING) && defined (HAVE_MPS)
+  igc_check_freeable (block);
+#endif
   MALLOC_BLOCK_INPUT;
   free (block);
   MALLOC_UNBLOCK_INPUT;
diff --git a/src/igc.c b/src/igc.c
index f933438a640..f034aae9460 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -2989,6 +2989,20 @@ root_find (void *start)
   return NULL;
 }
 
+#ifdef ENABLE_CHECKING
+void
+igc_check_freeable (void *start)
+{
+  if (start)
+    {
+      struct igc_root_list *r = root_find (start);
+      igc_assert (r == NULL);
+      if (r != NULL)
+       emacs_abort ();
+    }
+}
+#endif
+
 void
 igc_destroy_root_with_start (void *start)
 {
diff --git a/src/igc.h b/src/igc.h
index 38fde71c2a1..d4be8e4c03d 100644
--- a/src/igc.h
+++ b/src/igc.h
@@ -86,6 +86,9 @@ struct Lisp_Buffer_Local_Value *igc_alloc_blv (void);
 void *igc_alloc_handler (void);
 void *igc_xzalloc_ambig (size_t size);
 void *igc_realloc_ambig (void *block, size_t size);
+#ifdef ENABLE_CHECKING
+void igc_check_freeable (void *p);
+#endif
 Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n);
 void * igc_xalloc_raw_exact (size_t n);
 



reply via email to

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