Don't return (or dereference) dangling pointer
Merge pull request #333 from nbougalis/cleanups

Don't return (or dereference) dangling pointer