# HG changeset patch # User Jason Rumney # Date 1230118632 0 # Node ID dbba9cb0e6cef5c3eb13b72de524ff0dce82fee0 # Parent 01f68a925d1282b6f9c29e66d5d52600ec377db4 Add comments to explain checks and aborts, to assist future debugging. diff -r 01f68a925d12 -r dbba9cb0e6ce src/ralloc.c --- 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;