Merge pull request #1 from spkrka/master

Fix memory leak on failure
Minimize allocations during iteration

Always allocate the upper bound for key and value up front
and reuse it during the iteration.