File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 57
57
58
58
fn cp_setup ( info : Vec < libosdp_sys:: osdp_pd_info_t > ) -> Result < * mut c_void > {
59
59
let ctx = unsafe { libosdp_sys:: osdp_cp_setup ( info. len ( ) as i32 , info. as_ptr ( ) ) } ;
60
+ for pd in info. into_iter ( ) {
61
+ crate :: drop_osdp_pd_info ( pd) ;
62
+ }
60
63
if ctx. is_null ( ) {
61
64
Err ( OsdpError :: Setup )
62
65
} else {
Original file line number Diff line number Diff line change 58
58
}
59
59
60
60
fn pd_setup ( mut info : PdInfo ) -> Result < * mut c_void > {
61
- let ctx = unsafe { libosdp_sys:: osdp_pd_setup ( & info. as_struct ( ) ) } ;
61
+ let info_struct = info. as_struct ( ) ;
62
+ let ctx = unsafe { libosdp_sys:: osdp_pd_setup ( & info_struct) } ;
63
+ crate :: drop_osdp_pd_info ( info_struct) ;
62
64
if ctx. is_null ( ) {
63
65
Err ( OsdpError :: Setup )
64
66
} else {
Original file line number Diff line number Diff line change @@ -279,3 +279,27 @@ impl PdInfo {
279
279
}
280
280
}
281
281
}
282
+
283
+ pub ( crate ) fn drop_osdp_pd_info ( info : libosdp_sys:: osdp_pd_info_t ) {
284
+ unsafe {
285
+ // The name is not copied by LibOSDP, so we cannot drop it here
286
+ // if !info.name.is_null() {
287
+ // drop(CString::from_raw(info.name as *mut _));
288
+ // }
289
+ if !info. cap . is_null ( ) {
290
+ let mut cap = info. cap as * mut libosdp_sys:: osdp_pd_cap ;
291
+ while ( * cap) . function_code != -1i8 as u8 {
292
+ cap = cap. add ( 1 ) ;
293
+ }
294
+ let len = ( cap. offset_from ( info. cap ) + 1 ) as usize ;
295
+ drop ( Vec :: from_raw_parts (
296
+ info. cap as * mut libosdp_sys:: osdp_pd_cap ,
297
+ len,
298
+ len,
299
+ ) ) ;
300
+ }
301
+ if !info. scbk . is_null ( ) {
302
+ drop ( Box :: from_raw ( info. scbk as * mut [ u8 ; 16 ] ) ) ;
303
+ }
304
+ }
305
+ }
You can’t perform that action at this time.
0 commit comments