Fix crashes due to incorrect ownership management of some returned objects, introduced in previous commit.