@@ -13,7 +13,7 @@ use crate::{
1313} ;
1414use handle_manager:: HandleManager ;
1515use log:: { debug, error} ;
16- use mbox :: MBox ;
16+ use malloced :: Malloced ;
1717use std:: collections:: HashMap ;
1818use std:: ptr:: null_mut;
1919
@@ -47,7 +47,7 @@ use std::ptr::null_mut;
4747pub struct Context {
4848 /// Handle for the ESYS context object owned through an Mbox.
4949 /// 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 > > ,
5151 sessions : (
5252 Option < AuthSession > ,
5353 Option < AuthSession > ,
@@ -105,7 +105,7 @@ impl Context {
105105 } ,
106106 ) ?;
107107
108- let esys_context = unsafe { Some ( MBox :: from_raw ( esys_context) ) } ;
108+ let esys_context = unsafe { Some ( Malloced :: from_raw ( esys_context) ) } ;
109109 Ok ( Context {
110110 esys_context,
111111 sessions : ( None , None , None ) ,
@@ -390,7 +390,7 @@ impl Context {
390390 fn mut_context ( & mut self ) -> * mut ESYS_CONTEXT {
391391 self . esys_context
392392 . as_mut ( )
393- . map ( MBox :: < ESYS_CONTEXT > :: as_mut_ptr)
393+ . map ( Malloced :: < ESYS_CONTEXT > :: as_mut_ptr)
394394 . unwrap ( ) // will only fail if called from Drop after .take()
395395 }
396396
@@ -440,8 +440,12 @@ impl Context {
440440
441441 /// Private function for handling that has been allocated with
442442 /// 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
445449 }
446450}
447451
@@ -476,7 +480,7 @@ impl Drop for Context {
476480 & mut self
477481 . esys_context
478482 . take ( )
479- . map ( MBox :: < ESYS_CONTEXT > :: into_raw)
483+ . map ( Malloced :: < ESYS_CONTEXT > :: into_raw)
480484 . unwrap ( ) , // should not fail based on how the context is initialised/used
481485 )
482486 } ;
0 commit comments