fix the leak that happens if krealloc fails
Merge pull request #28 from piki/fix-new_flags-leak

fix the leak that happens if krealloc fails