Fix memory leak + Windows support