Added NULL safety checks

These were reported as potential flaws by VeraCode scan.

> ### Unchecked Error Condition
> #### ￼Description
> The result of this call are not captured. Failing to check the return code can result in unexpected behavior.
> #### Recommendations
> Check the function return code for success