[metadata] Fix leaks when handling a few attributes (#16675)