]> git.lizzy.rs Git - rust.git/commitdiff
test that `environ` gets deallocated on changes
authorChristian Poveda <git@christianpoveda.xyz>
Sat, 7 Mar 2020 14:26:04 +0000 (09:26 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Sat, 7 Mar 2020 14:39:55 +0000 (09:39 -0500)
tests/compile-fail/environ-gets-deallocated.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/environ-gets-deallocated.rs b/tests/compile-fail/environ-gets-deallocated.rs
new file mode 100644 (file)
index 0000000..014c8c4
--- /dev/null
@@ -0,0 +1,10 @@
+extern "C" {
+    static environ: *const *const u8;
+}
+
+fn main() {
+    let pointer = unsafe { environ };
+    let _x = unsafe { *pointer };
+    std::env::set_var("FOO", "BAR");
+    let _y = unsafe { *pointer }; //~ ERROR dangling pointer was dereferenced
+}