File tree Expand file tree Collapse file tree 1 file changed +9
-17
lines changed
Expand file tree Collapse file tree 1 file changed +9
-17
lines changed Original file line number Diff line number Diff line change @@ -89,23 +89,15 @@ where
8989 * count = len;
9090
9191 if len == 0 {
92- ptr:: null_mut ( )
93- } else {
94- let mut res = Vec :: with_capacity ( len + 1 ) ;
95-
96- res. push ( len as u32 ) ;
97-
98- for i in items {
99- res. push ( i) ;
100- }
101-
102- assert ! ( res. len( ) == len + 1 ) ;
92+ return ptr:: null_mut ( ) ;
93+ }
10394
104- let raw = res . as_mut_ptr ( ) ;
105- mem :: forget ( res ) ;
95+ let res : Box < [ _ ] > = [ len as u32 ] . into_iter ( ) . chain ( items ) . collect ( ) ;
96+ debug_assert ! ( res . len ( ) == len + 1 ) ;
10697
107- unsafe { raw. offset ( 1 ) }
108- }
98+ // it's free on the function below: `cb_free_register_list`
99+ let raw = Box :: leak ( res) ;
100+ & mut raw[ 1 ]
109101 }
110102
111103 extern "C" fn cb_free_register_list ( _ctxt : * mut c_void , regs : * mut u32 ) {
@@ -115,8 +107,8 @@ where
115107 }
116108
117109 let actual_start = regs. offset( -1 ) ;
118- let len = * actual_start + 1 ;
119- let _regs = Vec :: from_raw_parts ( actual_start, len as usize , len as usize ) ;
110+ let len = ( * actual_start) + 1 ;
111+ let _regs = Box :: from_raw ( ptr :: slice_from_raw_parts_mut ( actual_start, len as usize ) ) ;
120112 } )
121113 }
122114
You can’t perform that action at this time.
0 commit comments