Fix memory leak when an error occurs encoding dict items, fixes #109

Fix for #109