BUG: fix leak and possible null dereference
Merge pull request #3372 from juliantaylor/datetime-leak

BUG: fix leak and possible use after free