diff src/libpam/memory.rs @ 100:3f11b8d30f63

Implement environment variable management. This actually wires up the environment variable handling to libpam, so that applications and modules can manage the environment through the authentication process.
author Paul Fisher <paul@pfish.zone>
date Tue, 24 Jun 2025 17:08:01 -0400
parents b87100c5eed4
children
line wrap: on
line diff
--- a/src/libpam/memory.rs	Tue Jun 24 14:54:47 2025 -0400
+++ b/src/libpam/memory.rs	Tue Jun 24 17:08:01 2025 -0400
@@ -6,7 +6,7 @@
 use std::ffi::{c_char, CStr, CString};
 use std::fmt::{Display, Formatter, Result as FmtResult};
 use std::marker::{PhantomData, PhantomPinned};
-use std::mem::offset_of;
+use std::mem::{offset_of, ManuallyDrop};
 use std::ops::{Deref, DerefMut};
 use std::ptr::NonNull;
 use std::result::Result as StdResult;
@@ -96,9 +96,7 @@
 
     /// Converts this CBox into a raw pointer.
     pub fn into_ptr(this: Self) -> NonNull<T> {
-        let ret = this.0;
-        mem::forget(this);
-        ret
+        ManuallyDrop::new(this).0
     }
 
     /// Gets a pointer from this but doesn't convert this into a raw pointer.
@@ -177,9 +175,8 @@
     ///
     /// You are responsible for freeing it later.
     pub fn into_ptr(self) -> NonNull<c_char> {
-        let ptr = CHeapBox::as_ptr(&self.0);
-        mem::forget(self);
-        ptr
+        let this = ManuallyDrop::new(self);
+        CHeapBox::as_ptr(&this.0)
     }
 
     /// Converts this into a dumb box. It will no longer be zeroed upon drop.