Fixes the crash in issue #574

Not sure about the memory management, though :-)