コード例 #1
0
ファイル: testharness.cpp プロジェクト: stevee2/Leaks
int main()
{
  init();
  {
    char *ptr = 0, *ptr1 = 0, *ptr2 = 0, *ptr4 = 0, *ptr5 = 0, *ptr6 = 0, *ptr7 = 0;

    // Test MALLOC
    ptr = (char*)DEBUG_MALLOC(256);
    strcpy(ptr, "ptr");

    // Test MALLOC
    ptr1 = (char*)DEBUG_MALLOC(256);
    strcpy(ptr1, "ptr1");

    // Test malloc
    ptr2 = (char*)malloc(256);
    strcpy(ptr2, "ptr2");

    // Test new
    int* ptr3 = DEBUG_NEW int(65);

    {
      // checkpoint_charlie takes care of the checkpoint, giving it a name, 
      // and dumping out any memory leaks detected after scope drop
      leaks::checkpoint_charlie checkpoint1("CHECKPOINT 1");

      // Test new[]
      ptr4 = DEBUG_NEW char[256];
      strcpy(ptr4, "ptr4");

      ptr5 = DEBUG_NEW char[256];
      strcpy(ptr5, "ptr5");
    //}
    //{
      leaks::checkpoint_charlie checkpoint2("CHECKPOINT 2");
      ptr6 = new char[256];
      strcpy(ptr6, "ptr6");

      ptr7 = (char*)DEBUG_MALLOC(256);
      strcpy(ptr7, "ptr7");
      ptr7 = (char*)DEBUG_REALLOC(ptr7, 256);
    }

    // Housekeeping
    LOG_PRINTF(("Housekeeping"));
    DEBUG_FREE(ptr);
    DEBUG_FREE(ptr1);
    free(ptr2);
    delete ptr3;
    delete [] ptr4;
    delete [] ptr5;
    delete [] ptr6;

    // Dump the current leaks
    DEBUG_DUMP();
  }
  while(true) SVC_WAIT(1000); // Stay here
}
コード例 #2
0
ファイル: dump.c プロジェクト: 3125788/android_toolchain_gdb
main()
{
  int i;

  for (i = 0; i < ARRSIZE; i++)
    intarray[i] = i+1;

  intstruct.a = 12 * 1;
  intstruct.b = 12 * 2;
  intstruct.c = 12 * 3;
  intstruct.d = 12 * 4;
  intstruct.e = 12 * 5;
  intstruct.f = 12 * 6;
  intstruct.g = 12 * 7;

  checkpoint1 ();
}