Skip to content

Commit

Permalink
Return null if it fails to allocate memory.
Browse files Browse the repository at this point in the history
std::alloc() can fail and return a null.  We return a null to give the
caller a chance to handle it. (Issue #10)

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
  • Loading branch information
Kui-Feng Lee authored and ThinkerYzu1 committed Oct 5, 2022
1 parent 45ecd94 commit 7bfc553
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,9 @@ unsafe fn convert_symbolizedresults_to_c(
+ mem::size_of::<blazesym_csym>() * all_csym_size;
let raw_buf_with_sz =
alloc(Layout::from_size_align(buf_size + mem::size_of::<u64>(), 8).unwrap());
if raw_buf_with_sz.is_null() {
return ptr::null();
}

// prepend an u64 to keep the size of the buffer.
*(raw_buf_with_sz as *mut u64) = buf_size as u64;
Expand Down

0 comments on commit 7bfc553

Please sign in to comment.