Mercurial > emacs
comparison src/ralloc.c @ 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 | e038c1a8307c |
comparison
equal
deleted
inserted
replaced
| 100673:01f68a925d12 | 100674:dbba9cb0e6ce |
|---|---|
| 400 { | 400 { |
| 401 register bloc_ptr p = first_bloc; | 401 register bloc_ptr p = first_bloc; |
| 402 | 402 |
| 403 while (p != NIL_BLOC) | 403 while (p != NIL_BLOC) |
| 404 { | 404 { |
| 405 /* Consistency check. Don't return inconsistent blocs. | |
| 406 Don't abort here, as callers might be expecting this, but | |
| 407 callers that always expect a bloc to be returned should abort | |
| 408 if one isn't to avoid a memory corruption bug that is | |
| 409 difficult to track down. */ | |
| 405 if (p->variable == ptr && p->data == *ptr) | 410 if (p->variable == ptr && p->data == *ptr) |
| 406 return p; | 411 return p; |
| 407 | 412 |
| 408 p = p->next; | 413 p = p->next; |
| 409 } | 414 } |
| 979 if (! r_alloc_initialized) | 984 if (! r_alloc_initialized) |
| 980 r_alloc_init (); | 985 r_alloc_init (); |
| 981 | 986 |
| 982 dead_bloc = find_bloc (ptr); | 987 dead_bloc = find_bloc (ptr); |
| 983 if (dead_bloc == NIL_BLOC) | 988 if (dead_bloc == NIL_BLOC) |
| 984 abort (); | 989 abort (); /* Double free? PTR not originally used to allocate? */ |
| 985 | 990 |
| 986 free_bloc (dead_bloc); | 991 free_bloc (dead_bloc); |
| 987 *ptr = 0; | 992 *ptr = 0; |
| 988 | 993 |
| 989 #ifdef emacs | 994 #ifdef emacs |
| 1023 return r_alloc (ptr, 0); | 1028 return r_alloc (ptr, 0); |
| 1024 } | 1029 } |
| 1025 | 1030 |
| 1026 bloc = find_bloc (ptr); | 1031 bloc = find_bloc (ptr); |
| 1027 if (bloc == NIL_BLOC) | 1032 if (bloc == NIL_BLOC) |
| 1028 abort (); | 1033 abort (); /* Already freed? PTR not originally used to allocate? */ |
| 1029 | 1034 |
| 1030 if (size < bloc->size) | 1035 if (size < bloc->size) |
| 1031 { | 1036 { |
| 1032 /* Wouldn't it be useful to actually resize the bloc here? */ | 1037 /* Wouldn't it be useful to actually resize the bloc here? */ |
| 1033 /* I think so too, but not if it's too expensive... */ | 1038 /* I think so too, but not if it's too expensive... */ |
| 1244 | 1249 |
| 1245 bloc = bloc->next; | 1250 bloc = bloc->next; |
| 1246 } | 1251 } |
| 1247 | 1252 |
| 1248 if (bloc == NIL_BLOC || bloc->variable != old) | 1253 if (bloc == NIL_BLOC || bloc->variable != old) |
| 1249 abort (); | 1254 abort (); /* Already freed? OLD not originally used to allocate? */ |
| 1250 | 1255 |
| 1251 /* Update variable to point to the new location. */ | 1256 /* Update variable to point to the new location. */ |
| 1252 bloc->variable = new; | 1257 bloc->variable = new; |
| 1253 } | 1258 } |
| 1254 | 1259 |
