If key isn't reliably a string, then xstrdup() isn't the right tool to use here.
Sounds like another xmemdup().