Skip to content

Commit 27414c9

Browse files
authored
Merge pull request #2522 from serde-rs/leak
Leak all memory allocated during macro expansion
2 parents 22be673 + 50e2f4b commit 27414c9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

precompiled/bin/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@ extern crate proc_macro2;
22

33
use proc_macro2::watt;
44
use proc_macro2::watt::buffer::InputBuffer;
5+
use std::alloc::{GlobalAlloc, Layout, System};
56
use std::io::{self, Read, Write};
67
use std::sync::atomic::Ordering;
78

9+
struct MonotonicAllocator;
10+
11+
#[global_allocator]
12+
static ALLOCATOR: MonotonicAllocator = MonotonicAllocator;
13+
14+
unsafe impl GlobalAlloc for MonotonicAllocator {
15+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
16+
System.alloc(layout)
17+
}
18+
19+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
20+
// Leak: this cuts 3% of code size from the precompiled macro binary.
21+
// There is no way that serde_derive would fill up all memory on the
22+
// host. When the subprocess exits, operating system will clean this up.
23+
}
24+
}
25+
826
fn main() {
927
let mut buf = Vec::new();
1028
io::stdin().read_to_end(&mut buf).unwrap();

0 commit comments

Comments
 (0)