mirror of
https://github.com/gperftools/gperftools
synced 2025-01-06 22:49:42 +00:00
avoid semi-bogus use-after-free warning
In heap checker we actually use test_str address after deletion, to verify at runtime that heap checker is indeed tracking deletions. But gcc barks. So lets hide allocation from it by calling tc_newarray/tc_deletearray. Refers to #1401
This commit is contained in:
parent
9d46f1e890
commit
e63d2f855d
@ -71,6 +71,7 @@
|
|||||||
#include <gperftools/malloc_extension.h>
|
#include <gperftools/malloc_extension.h>
|
||||||
#include <gperftools/malloc_hook.h>
|
#include <gperftools/malloc_hook.h>
|
||||||
#include <gperftools/stacktrace.h>
|
#include <gperftools/stacktrace.h>
|
||||||
|
#include <gperftools/tcmalloc.h>
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/commandlineflags.h"
|
#include "base/commandlineflags.h"
|
||||||
@ -2118,13 +2119,15 @@ void HeapLeakChecker_InternalInitStart() {
|
|||||||
// and heap profiler is indeed able to keep track
|
// and heap profiler is indeed able to keep track
|
||||||
// of the objects being allocated.
|
// of the objects being allocated.
|
||||||
// We test this to make sure we are indeed checking for leaks.
|
// We test this to make sure we are indeed checking for leaks.
|
||||||
char* test_str = new char[5];
|
char* test_str = new (tc_newarray(5)) char[5];
|
||||||
size_t size;
|
size_t size;
|
||||||
{ SpinLockHolder l(&heap_checker_lock);
|
{ SpinLockHolder l(&heap_checker_lock);
|
||||||
RAW_CHECK(heap_profile->FindAlloc(test_str, &size),
|
RAW_CHECK(heap_profile->FindAlloc(test_str, &size),
|
||||||
"our own new/delete not linked?");
|
"our own new/delete not linked?");
|
||||||
}
|
}
|
||||||
delete[] test_str;
|
|
||||||
|
tc_deletearray(test_str);
|
||||||
|
|
||||||
{ SpinLockHolder l(&heap_checker_lock);
|
{ SpinLockHolder l(&heap_checker_lock);
|
||||||
// This check can fail when it should not if another thread allocates
|
// This check can fail when it should not if another thread allocates
|
||||||
// into this same spot right this moment,
|
// into this same spot right this moment,
|
||||||
|
Loading…
Reference in New Issue
Block a user