Fix Compilation Bugs

missing includes
Fix Memmory leak

used delete instead of free on malloc pointer