@@ -13,7 +13,7 @@ use crate::{
13
13
} ;
14
14
use handle_manager:: HandleManager ;
15
15
use log:: { debug, error} ;
16
- use mbox :: MBox ;
16
+ use malloced :: Malloced ;
17
17
use std:: collections:: HashMap ;
18
18
use std:: ptr:: null_mut;
19
19
@@ -47,7 +47,7 @@ use std::ptr::null_mut;
47
47
pub struct Context {
48
48
/// Handle for the ESYS context object owned through an Mbox.
49
49
/// Wrapping the handle in an optional Mbox is done to allow the `Context` to be closed properly when the `Context` structure is dropped.
50
- esys_context : Option < MBox < ESYS_CONTEXT > > ,
50
+ esys_context : Option < Malloced < ESYS_CONTEXT > > ,
51
51
sessions : (
52
52
Option < AuthSession > ,
53
53
Option < AuthSession > ,
@@ -105,7 +105,7 @@ impl Context {
105
105
} ,
106
106
) ?;
107
107
108
- let esys_context = unsafe { Some ( MBox :: from_raw ( esys_context) ) } ;
108
+ let esys_context = unsafe { Some ( Malloced :: from_raw ( esys_context) ) } ;
109
109
Ok ( Context {
110
110
esys_context,
111
111
sessions : ( None , None , None ) ,
@@ -390,7 +390,7 @@ impl Context {
390
390
fn mut_context ( & mut self ) -> * mut ESYS_CONTEXT {
391
391
self . esys_context
392
392
. as_mut ( )
393
- . map ( MBox :: < ESYS_CONTEXT > :: as_mut_ptr)
393
+ . map ( Malloced :: < ESYS_CONTEXT > :: as_mut_ptr)
394
394
. unwrap ( ) // will only fail if called from Drop after .take()
395
395
}
396
396
@@ -440,8 +440,12 @@ impl Context {
440
440
441
441
/// Private function for handling that has been allocated with
442
442
/// C memory allocation functions in TSS.
443
- fn ffi_data_to_owned < T > ( data_ptr : * mut T ) -> T {
444
- MBox :: into_inner ( unsafe { MBox :: from_raw ( data_ptr) } )
443
+ fn ffi_data_to_owned < T : Copy > ( data_ptr : * mut T ) -> T {
444
+ let out = unsafe { * data_ptr } ;
445
+
446
+ // Free the malloced data.
447
+ drop ( unsafe { Malloced :: from_raw ( data_ptr) } ) ;
448
+ out
445
449
}
446
450
}
447
451
@@ -476,7 +480,7 @@ impl Drop for Context {
476
480
& mut self
477
481
. esys_context
478
482
. take ( )
479
- . map ( MBox :: < ESYS_CONTEXT > :: into_raw)
483
+ . map ( Malloced :: < ESYS_CONTEXT > :: into_raw)
480
484
. unwrap ( ) , // should not fail based on how the context is initialised/used
481
485
)
482
486
} ;
0 commit comments