Fix memory leaks introduced by commit eca2b9b