Mercurial > hg > xemacs-beta
comparison src/free-hook.c @ 267:966663fcf606 r20-5b32
Import from CVS: tag r20-5b32
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:26:29 +0200 |
parents | 52952cbfc5b5 |
children | b2472a1930f2 |
comparison
equal
deleted
inserted
replaced
266:18d185df8c54 | 267:966663fcf606 |
---|---|
75 #include "lisp.h" | 75 #include "lisp.h" |
76 #else | 76 #else |
77 void *malloc (unsigned long); | 77 void *malloc (unsigned long); |
78 #endif | 78 #endif |
79 | 79 |
80 #if !defined(HAVE_LIBMCHECK) | |
80 #include <stdio.h> | 81 #include <stdio.h> |
81 | 82 |
82 #include "hash.h" | 83 #include "hash.h" |
83 | 84 |
84 #ifdef UNMAPPED_FREE | 85 #ifdef UNMAPPED_FREE |
223 | 224 |
224 if (!present) | 225 if (!present) |
225 { | 226 { |
226 /* This can only happen if you try to free something that didn't | 227 /* This can only happen if you try to free something that didn't |
227 come from malloc */ | 228 come from malloc */ |
228 if (strict_free_check) | 229 #if 1 |
229 abort (); | 230 /* I originally wrote: "There's really no need to drop core." |
230 else | 231 I have seen the error of my ways. -slb */ |
231 { | 232 if (strict_free_check) |
232 __free_hook = check_free; | 233 { |
233 __malloc_hook = check_malloc; | 234 abort (); |
234 goto end; | 235 } |
235 } | 236 #endif |
237 printf("Freeing unmalloc'ed memory at %p\n", ptr); | |
238 __free_hook = check_free; | |
239 __malloc_hook = check_malloc; | |
240 goto end; | |
236 } | 241 } |
237 | 242 |
238 if (size < 0) | 243 if (size < 0) |
239 { | 244 { |
240 /* This happens when you free twice */ | 245 /* This happens when you free twice */ |
241 if (strict_free_check) | 246 #if 1 |
242 abort (); | 247 /* See above comment. */ |
243 else | 248 if (strict_free_check) |
244 { | 249 { |
245 __free_hook = check_free; | 250 abort (); |
246 __malloc_hook = check_malloc; | 251 } |
247 goto end; | 252 #endif |
248 } | 253 printf("Freeing %p twice\n", ptr); |
254 __free_hook = check_free; | |
255 __malloc_hook = check_malloc; | |
256 goto end; | |
249 } | 257 } |
258 | |
250 puthash (ptr, (void *)-size, pointer_table); | 259 puthash (ptr, (void *)-size, pointer_table); |
251 #ifdef UNMAPPED_FREE | 260 #ifdef UNMAPPED_FREE |
252 /* Round up size to an even number of pages. */ | 261 /* Round up size to an even number of pages. */ |
253 rounded_up_size = ROUND_UP_TO_PAGE (size); | 262 rounded_up_size = ROUND_UP_TO_PAGE (size); |
254 /* Protect the pages freed from all access */ | 263 /* Protect the pages freed from all access */ |
343 unsigned long old_size; | 352 unsigned long old_size; |
344 void *result = malloc (size); | 353 void *result = malloc (size); |
345 | 354 |
346 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size); | 355 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size); |
347 if (!present) | 356 if (!present) |
357 { | |
348 /* This can only happen by reallocing a pointer that didn't | 358 /* This can only happen by reallocing a pointer that didn't |
349 come from malloc. */ | 359 come from malloc. */ |
350 abort (); | 360 #if 1 |
361 /* see comment in check_free(). */ | |
362 abort (); | |
363 #endif | |
364 printf("Realloc'ing unmalloc'ed pointer at %p\n", ptr); | |
365 } | |
366 | |
351 if (result == 0) | 367 if (result == 0) |
352 goto end; | 368 goto end; |
353 memcpy (result, ptr, MIN (size, old_size)); | 369 memcpy (result, ptr, MIN (size, old_size)); |
354 free (ptr); | 370 free (ptr); |
355 end: | 371 end: |
488 void (*__free_hook)() = check_free; | 504 void (*__free_hook)() = check_free; |
489 void *(*__malloc_hook)() = check_malloc; | 505 void *(*__malloc_hook)() = check_malloc; |
490 void *(*__realloc_hook)() = check_realloc; | 506 void *(*__realloc_hook)() = check_realloc; |
491 #endif | 507 #endif |
492 | 508 |
509 #endif /* !defined(HAVE_LIBMCHECK) */ | |
493 | 510 |
494 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO) | 511 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO) |
495 | 512 |
496 /* Note: There is no more input blocking in XEmacs */ | 513 /* Note: There is no more input blocking in XEmacs */ |
497 typedef enum { | 514 typedef enum { |