Merge pull request #55 from domob1812/leaks

Free some memory properly on shutdown.