[metadata] Fix leak in custom attribute lookup (#19279)