DE1541. Fix access of uninitialized variable in measures2csv.

Also restore memory leak and buffer overflow fixes.