isn't it leaking? I'd use scope_ptr here