Sanitize against NULL in some free-like functions.
Merge pull request #1018 from lioncash/free

Sanitize against NULL in some free-like functions.