changeset 100674:dbba9cb0e6ce

Add comments to explain checks and aborts, to assist future debugging.
author Jason Rumney <jasonr@gnu.org>
date Wed, 24 Dec 2008 11:37:12 +0000
parents 01f68a925d12
children 7bd3f6af5679
files src/ralloc.c
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ralloc.c	Wed Dec 24 11:20:32 2008 +0000
+++ b/src/ralloc.c	Wed Dec 24 11:37:12 2008 +0000
@@ -402,6 +402,11 @@
 
   while (p != NIL_BLOC)
     {
+      /* Consistency check. Don't return inconsistent blocs.
+	 Don't abort here, as callers might be expecting this,  but
+	 callers that always expect a bloc to be returned should abort
+	 if one isn't to avoid a memory corruption bug that is
+	 difficult to track down.  */
       if (p->variable == ptr && p->data == *ptr)
 	return p;
 
@@ -981,7 +986,7 @@
 
   dead_bloc = find_bloc (ptr);
   if (dead_bloc == NIL_BLOC)
-    abort ();
+    abort (); /* Double free? PTR not originally used to allocate?  */
 
   free_bloc (dead_bloc);
   *ptr = 0;
@@ -1025,7 +1030,7 @@
 
   bloc = find_bloc (ptr);
   if (bloc == NIL_BLOC)
-    abort ();
+    abort (); /* Already freed? PTR not originally used to allocate?  */
 
   if (size < bloc->size)
     {
@@ -1246,7 +1251,7 @@
     }
 
   if (bloc == NIL_BLOC || bloc->variable != old)
-    abort ();
+    abort (); /* Already freed? OLD not originally used to allocate?  */
 
   /* Update variable to point to the new location.  */
   bloc->variable = new;