-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest038.cc
More file actions
31 lines (26 loc) · 746 Bytes
/
test038.cc
File metadata and controls
31 lines (26 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "dmalloc.hh"
#include <cstdio>
#include <cassert>
#include <cstring>
// Wild free inside heap-allocated data.
struct whatever {
int first[100];
char second[3000];
int third[200];
};
int main(int argc, char** argv) {
dmalloc_allocator<whatever> allocator;
// “allocate space for one `whatever` object”
whatever* object = allocator.allocate(1);
uintptr_t addr = reinterpret_cast<uintptr_t>(object);
if (argc < 2) {
addr += 3000;
} else {
addr += strtol(argv[1], nullptr, 0);
}
whatever* trick = reinterpret_cast<whatever*>(addr);
allocator.deallocate(trick, 1);
dmalloc_print_statistics();
}
//! MEMORY BUG???: invalid free of pointer ???, not allocated
//! ???