Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak all memory allocated during macro expansion #2522

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions precompiled/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@ extern crate proc_macro2;

use proc_macro2::watt;
use proc_macro2::watt::buffer::InputBuffer;
use std::alloc::{GlobalAlloc, Layout, System};
use std::io::{self, Read, Write};
use std::sync::atomic::Ordering;

struct MonotonicAllocator;

#[global_allocator]
static ALLOCATOR: MonotonicAllocator = MonotonicAllocator;

unsafe impl GlobalAlloc for MonotonicAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
System.alloc(layout)
}

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
// Leak: this cuts 3% of code size from the precompiled macro binary.
// There is no way that serde_derive would fill up all memory on the
// host. When the subprocess exits, operating system will clean this up.
}
}

fn main() {
let mut buf = Vec::new();
io::stdin().read_to_end(&mut buf).unwrap();
Expand Down