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 @@ -798,6 +798,9 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_create(flags: c_uint) -> *
798798 let bytes = secp256k1_context_preallocated_size ( flags) + ALIGN_TO ;
799799 let layout = alloc:: Layout :: from_size_align ( bytes, ALIGN_TO ) . unwrap ( ) ;
800800 let ptr = alloc:: alloc ( layout) ;
801+ if ptr. is_null ( ) {
802+ alloc:: handle_alloc_error ( layout) ;
803+ }
801804 ( ptr as * mut usize ) . write ( bytes) ;
802805 // We must offset a whole ALIGN_TO in order to preserve the same alignment
803806 // this means we "lose" ALIGN_TO-size_of(usize) for padding.
Original file line number Diff line number Diff line change @@ -194,6 +194,9 @@ mod alloc_only {
194194 let size = unsafe { ffi:: secp256k1_context_preallocated_size ( C :: FLAGS ) } ;
195195 let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
196196 let ptr = unsafe { alloc:: alloc ( layout) } ;
197+ if ptr. is_null ( ) {
198+ alloc:: handle_alloc_error ( layout) ;
199+ }
197200
198201 #[ allow( unused_mut) ] // ctx is not mutated under some feature combinations.
199202 let mut ctx = Secp256k1 {
@@ -254,6 +257,9 @@ mod alloc_only {
254257 let size = unsafe { ffi:: secp256k1_context_preallocated_clone_size ( self . ctx as _ ) } ;
255258 let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
256259 let ptr = unsafe { alloc:: alloc ( layout) } ;
260+ if ptr. is_null ( ) {
261+ alloc:: handle_alloc_error ( layout) ;
262+ }
257263 Secp256k1 {
258264 ctx : unsafe {
259265 ffi:: secp256k1_context_preallocated_clone ( self . ctx , ptr as * mut c_void )
You can’t perform that action at this time.
0 commit comments