Memory leak fix

Rebased against unstable...