Fixing memory leaks in the SWIG wrapper.