proper freecursor handling (thanks hirato/lamiae)