home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / aros / nastyfreemem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.2 KB  |  99 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: nastyfreemem.c,v 1.6 1997/01/27 00:17:41 ldp Exp $
  4.     $Log: nastyfreemem.c,v $
  5.     Revision 1.6  1997/01/27 00:17:41  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.5  1996/12/10 13:59:44  aros
  9.     Moved #include into first column to allow makedepend to see it.
  10.  
  11.     Revision 1.4  1996/09/21 15:47:33  digulla
  12.     Use Amiga types
  13.  
  14.     Revision 1.3  1996/09/11 16:50:52  digulla
  15.     Moved PurgeChunk() to here to avoid problems during link
  16.  
  17.     Revision 1.2  1996/08/16 14:03:26  digulla
  18.     NastyFreeMem() should itself call FreeMem, no matter what :)
  19.  
  20.     Revision 1.1  1996/08/15 14:39:42  digulla
  21.     Delete contents of memory before freeing it
  22.  
  23.     Revision 1.1  1996/08/15 13:24:20  digulla
  24.     New function: kprintf() allows to print a text which is always shown to the
  25.     user no matter what.
  26.  
  27.     Revision 1.1  1996/08/01 18:46:31  digulla
  28.     Simple string compare function
  29.  
  30.     Desc:
  31.     Lang:
  32. */
  33. #include <aros/system.h>
  34. #include <exec/execbase.h>
  35. #undef FreeMem /* Don't use any kind of macro here :) We want the real thing */
  36. #include <proto/exec.h>
  37.  
  38. extern struct ExecBase * SysBase;
  39. extern void PurgeChunk (ULONG *, ULONG);
  40.  
  41. /*****************************************************************************
  42.  
  43.     NAME */
  44. #include <proto/aros.h>
  45.  
  46.     void NastyFreeMem (
  47.  
  48. /*  SYNOPSIS */
  49.     APTR  mem,
  50.     ULONG size)
  51.  
  52. /*  FUNCTION
  53.     Overwrites the memory with 0xDEADBEEF before actually freeing it.
  54.  
  55.     INPUTS
  56.     mem - Pointer which was returned by AllocMem()
  57.     size - Size which was given to AllocMem()
  58.  
  59.     RESULT
  60.     The function may print some infos using kprintf().
  61.  
  62.     NOTES
  63.     This function depends on SysBase.
  64.  
  65.     EXAMPLE
  66.  
  67.     BUGS
  68.  
  69.     SEE ALSO
  70.     FreeMem()
  71.  
  72.     INTERNALS
  73.  
  74.     HISTORY
  75.     24-12-95    digulla created
  76.  
  77. ******************************************************************************/
  78. {
  79.     PurgeChunk ((ULONG *)mem, size);
  80.     FreeMem (mem, size);
  81. } /* NastyFreeMem */
  82.  
  83.  
  84. /* Don't use #if on this one since it may be used by some other routine, too.
  85.     It's not static by design. */
  86. void PurgeChunk (ULONG * ptr, ULONG size)
  87. {
  88.     while (size >= sizeof (ULONG))
  89.     {
  90. #if SIZEOFULONG > 4
  91.     *ptr ++ = 0xDEAFBEEFDEADBEEFL;
  92. #else
  93.     *ptr ++ = 0xDEAFBEEFL;
  94. #endif
  95.     size -= sizeof (ULONG);
  96.     }
  97. }
  98.  
  99.