Fix memory leak if krealloc() fails

Fix memory leak of new_flags if realloc of h->keys or h->vals fails.