Patch from Scott McKellar which plugs a couple of memory leaks, and