Skip to content

Latest commit

 

History

History

Program-02

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Problem 02

Description

Validation suggestion to check if malloc returned NULL in great article Code memory safety and efficiency by example written by Marty Kalin on opensource.com.

In the section 'Heap storage', I noticed that the main function checks if the /* malloc failed */, but since we are initializing *heap_nums in the same function (get_heap_array) we are trying to allocate memory, we need to add validation before trying to access the array to avoid segmentation failure (SIGSEGV) in case of allocation failure.²

References

1 - Code memory safety and efficiency by example

2 - My comment on the article