File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -811,6 +811,9 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_create(flags: c_uint) -> *
811811 let bytes = secp256k1_context_preallocated_size ( flags) + ALIGN_TO ;
812812 let layout = alloc:: Layout :: from_size_align ( bytes, ALIGN_TO ) . unwrap ( ) ;
813813 let ptr = alloc:: alloc ( layout) ;
814+ if ptr. is_null ( ) {
815+ alloc:: handle_alloc_error ( layout) ;
816+ }
814817 ( ptr as * mut usize ) . write ( bytes) ;
815818 // We must offset a whole ALIGN_TO in order to preserve the same alignment
816819 // this means we "lose" ALIGN_TO-size_of(usize) for padding.
Original file line number Diff line number Diff line change @@ -202,6 +202,9 @@ mod alloc_only {
202202 let size = unsafe { ffi:: secp256k1_context_preallocated_size ( C :: FLAGS ) } ;
203203 let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
204204 let ptr = unsafe { alloc:: alloc ( layout) } ;
205+ if ptr. is_null ( ) {
206+ alloc:: handle_alloc_error ( layout) ;
207+ }
205208
206209 #[ allow( unused_mut) ] // ctx is not mutated under some feature combinations.
207210 let mut ctx = Secp256k1 {
@@ -262,6 +265,9 @@ mod alloc_only {
262265 let size = unsafe { ffi:: secp256k1_context_preallocated_clone_size ( self . ctx as _ ) } ;
263266 let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
264267 let ptr = unsafe { alloc:: alloc ( layout) } ;
268+ if ptr. is_null ( ) {
269+ alloc:: handle_alloc_error ( layout) ;
270+ }
265271 Secp256k1 {
266272 ctx : unsafe {
267273 ffi:: secp256k1_context_preallocated_clone ( self . ctx , ptr as * mut c_void )
You can’t perform that action at this time.
0 commit comments