1 //@ignore-target-windows: Windows does not have a global environ list that the program can access directly
3 #[cfg(any(target_os = "linux", target_os = "freebsd"))]
4 fn get_environ() -> *const *const u8 {
6 static mut environ: *const *const u8;
11 #[cfg(target_os = "macos")]
12 fn get_environ() -> *const *const u8 {
14 fn _NSGetEnviron() -> *mut *const *const u8;
16 unsafe { *_NSGetEnviron() }
20 let pointer = get_environ();
21 let _x = unsafe { *pointer };
22 std::env::set_var("FOO", "BAR");
23 let _y = unsafe { *pointer }; //~ ERROR: dereferenced after this allocation got freed