wip: initial work on tracking source of an allocation in debug mode

This commit is contained in:
daan 2020-02-11 09:37:26 -08:00
parent 0a77b7423f
commit 4090561975
10 changed files with 381 additions and 164 deletions

View file

@ -11,6 +11,7 @@ static void double_free1();
static void double_free2();
static void corrupt_free();
static void block_overflow1();
static void dangling_ptr_write();
int main() {
mi_version();
@ -20,6 +21,7 @@ int main() {
// double_free2();
// corrupt_free();
// block_overflow1();
dangling_ptr_write();
void* p1 = malloc(78);
void* p2 = malloc(24);
@ -49,6 +51,14 @@ static void block_overflow1() {
free(p);
}
static void dangling_ptr_write() {
for (int i = 0; i < 1000; i++) {
uint8_t* p = (uint8_t*)mi_malloc(16);
free(p);
p[0] = 0;
}
}
// The double free samples come ArcHeap [1] by Insu Yun (issue #161)
// [1]: https://arxiv.org/pdf/1903.00503.pdf

View file

@ -23,10 +23,12 @@ public:
~Test() { }
};
void dangling_ptr_write();
int main() {
mi_stats_reset(); // ignore earlier allocations
atexit(free_p);
dangling_ptr_write();
void* p1 = malloc(78);
void* p2 = mi_malloc_aligned(16,24);
free(p1);
@ -53,6 +55,14 @@ int main() {
return 0;
}
static void dangling_ptr_write() {
for (int i = 0; i < 1000; i++) {
uint8_t* p = new uint8_t[16];
free(p);
p[0] = 0;
}
}
class Static {
private:
void* p;