Fix memory leaks and buffer overflows in measures2csv.