Fix: memory leaks introduced in previous commit