Fix memory leakages