Update khash.h from upstream sources

Updated to attractivechaos/klib@7163c2137856c22bebce87fd8f68a37fbb84a430
and its parents, in particular fixing new_flags memory leaks (cf #138).
Fix various simple memory leaks (cf #138)