Failed attempts at fixing memory leak