Patching some memory leaks