Thanks for this PR! I noticed some functions return pointers that are then used and later freed. I guess that they have to be checked if they are `NULL`, expecting there will be crashes when they are used and they are `NULL`.
Added NULL checking to the PR.