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