home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / extras / memlib / example.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  999 b   |  37 lines

  1. #include <exec/memory.h>
  2. #include <proto/exec.h>
  3.  
  4. #include "memwatch.h" /* To enable memlib, you must #define MWDEBUG to 1 */
  5.  
  6. int main(void)
  7. {
  8.    char *a;
  9.  
  10.    a = AllocMem(20, 0);  /* Note that we never free this memory */
  11.  
  12.    a = AllocMem(10, 0);
  13.  
  14.    FreeMem(a, 9);  /* Note that we free an incorrect length here */
  15.  
  16.    a = AllocVec(10, 0);
  17.    
  18.    free(a);  /* Freed with wrong free routine */
  19.  
  20.    a = strdup("test"); /* Note that we never free this memory */
  21.  
  22.    a = getcwd(NULL, 1000);
  23.    free(a);
  24.    free(a);  /* Note that we're freeing the memory twice! */
  25.    
  26.    putenv("MWTest=xx");
  27.    a = getenv("MWTest");
  28.    if(a) a[strlen(a)+1] = 0;  /* Note we're trashing a byte!!!      */
  29.                               /* This shouldn't cause a real crash  */
  30.                               /* since malloc() allocates in clumps */
  31.                               /* of 4 bytes, and 'a' is 3 bytes.    */
  32.  
  33.    MWReport("At end of main()", MWR_FULL);  /* Generate a memory usage report */
  34.  
  35.    return(0);
  36. }
  37.