Fix memory leaks in index

Make valgrind smile + a few tiny fixes.