Fixed memory leaks

Went windows-only by using Kernel32.dll (because of GlobalFree())