Fixing various memory leaks according to the Slicer memory management tutorial.