Fix crash in UPNP code

Fixes #1773