| OLD | NEW |
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 #include <memory> | 94 #include <memory> |
| 95 #include <set> | 95 #include <set> |
| 96 #include <string> | 96 #include <string> |
| 97 #include <vector> | 97 #include <vector> |
| 98 | 98 |
| 99 #include "base/commandlineflags.h" | 99 #include "base/commandlineflags.h" |
| 100 #include "base/googleinit.h" | 100 #include "base/googleinit.h" |
| 101 #include "base/logging.h" | 101 #include "base/logging.h" |
| 102 #include "base/commandlineflags.h" | 102 #include "base/commandlineflags.h" |
| 103 #include "base/thread_lister.h" | 103 #include "base/thread_lister.h" |
| 104 #include <google/heap-checker.h> | 104 #include <gperftools/heap-checker.h> |
| 105 #include "memory_region_map.h" | 105 #include "memory_region_map.h" |
| 106 #include <google/malloc_extension.h> | 106 #include <gperftools/malloc_extension.h> |
| 107 #include <google/stacktrace.h> | 107 #include <gperftools/stacktrace.h> |
| 108 | 108 |
| 109 // On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old | 109 // On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old |
| 110 // form of the name instead. | 110 // form of the name instead. |
| 111 #ifndef MAP_ANONYMOUS | 111 #ifndef MAP_ANONYMOUS |
| 112 # define MAP_ANONYMOUS MAP_ANON | 112 # define MAP_ANONYMOUS MAP_ANON |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 using namespace std; | 115 using namespace std; |
| 116 | 116 |
| 117 // ========================================================================= // | 117 // ========================================================================= // |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 | 1374 |
| 1375 LOGF << "In main(): heap_check=" << FLAGS_heap_check << endl; | 1375 LOGF << "In main(): heap_check=" << FLAGS_heap_check << endl; |
| 1376 | 1376 |
| 1377 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good | 1377 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good |
| 1378 | 1378 |
| 1379 if (FLAGS_test_leak) { | 1379 if (FLAGS_test_leak) { |
| 1380 void* arr; | 1380 void* arr; |
| 1381 RunHidden(NewCallback(MakeALeak, &arr)); | 1381 RunHidden(NewCallback(MakeALeak, &arr)); |
| 1382 Use(&arr); | 1382 Use(&arr); |
| 1383 LogHidden("Leaking", arr); | 1383 LogHidden("Leaking", arr); |
| 1384 if (FLAGS_test_cancel_global_check) HeapLeakChecker::CancelGlobalCheck(); | 1384 if (FLAGS_test_cancel_global_check) { |
| 1385 HeapLeakChecker::CancelGlobalCheck(); |
| 1386 } else { |
| 1387 // Verify we can call NoGlobalLeaks repeatedly without deadlocking |
| 1388 HeapLeakChecker::NoGlobalLeaks(); |
| 1389 HeapLeakChecker::NoGlobalLeaks(); |
| 1390 } |
| 1385 return Pass(); | 1391 return Pass(); |
| 1386 // whole-program leak-check should (with very high probability) | 1392 // whole-program leak-check should (with very high probability) |
| 1387 // catch the leak of arr (10 * sizeof(int) bytes) | 1393 // catch the leak of arr (10 * sizeof(int) bytes) |
| 1388 // (when !FLAGS_test_cancel_global_check) | 1394 // (when !FLAGS_test_cancel_global_check) |
| 1389 } | 1395 } |
| 1390 | 1396 |
| 1391 if (FLAGS_test_loop_leak) { | 1397 if (FLAGS_test_loop_leak) { |
| 1392 void* arr1; | 1398 void* arr1; |
| 1393 void* arr2; | 1399 void* arr2; |
| 1394 RunHidden(NewCallback(MakeDeathLoop, &arr1, &arr2)); | 1400 RunHidden(NewCallback(MakeDeathLoop, &arr1, &arr2)); |
| 1395 Use(&arr1); | 1401 Use(&arr1); |
| 1396 Use(&arr2); | 1402 Use(&arr2); |
| 1397 LogHidden("Loop leaking", arr1); | 1403 LogHidden("Loop leaking", arr1); |
| 1398 LogHidden("Loop leaking", arr2); | 1404 LogHidden("Loop leaking", arr2); |
| 1399 if (FLAGS_test_cancel_global_check) HeapLeakChecker::CancelGlobalCheck(); | 1405 if (FLAGS_test_cancel_global_check) { |
| 1406 HeapLeakChecker::CancelGlobalCheck(); |
| 1407 } else { |
| 1408 // Verify we can call NoGlobalLeaks repeatedly without deadlocking |
| 1409 HeapLeakChecker::NoGlobalLeaks(); |
| 1410 HeapLeakChecker::NoGlobalLeaks(); |
| 1411 } |
| 1400 return Pass(); | 1412 return Pass(); |
| 1401 // whole-program leak-check should (with very high probability) | 1413 // whole-program leak-check should (with very high probability) |
| 1402 // catch the leak of arr1 and arr2 (4 * sizeof(void*) bytes) | 1414 // catch the leak of arr1 and arr2 (4 * sizeof(void*) bytes) |
| 1403 // (when !FLAGS_test_cancel_global_check) | 1415 // (when !FLAGS_test_cancel_global_check) |
| 1404 } | 1416 } |
| 1405 | 1417 |
| 1406 if (FLAGS_test_register_leak) { | 1418 if (FLAGS_test_register_leak) { |
| 1407 // make us fail only where the .sh test expects: | 1419 // make us fail only where the .sh test expects: |
| 1408 Pause(); | 1420 Pause(); |
| 1409 for (int i = 0; i < 100; ++i) { // give it some time to crash | 1421 for (int i = 0; i < 100; ++i) { // give it some time to crash |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 CHECK(heap_check.SameHeap()); | 1494 CHECK(heap_check.SameHeap()); |
| 1483 } else { | 1495 } else { |
| 1484 WARN_IF(heap_check.SameHeap() != true, | 1496 WARN_IF(heap_check.SameHeap() != true, |
| 1485 "overall leaks are caught; we must be using a stripped binary"); | 1497 "overall leaks are caught; we must be using a stripped binary"); |
| 1486 } | 1498 } |
| 1487 | 1499 |
| 1488 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good | 1500 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good |
| 1489 | 1501 |
| 1490 return Pass(); | 1502 return Pass(); |
| 1491 } | 1503 } |
| OLD | NEW |