Fixing a use after free