Fix bad memory hanlding.