Pre calculate constants as windows does not work otherwise
Fix memory leak in error case