preview: fix memleak and some rounding errors