Assert that we got storage
Assert allocation success
remove unused #includes
Replace strndup(), OS/X doesn't have it.
Remove unused #includes