fixed: some issues pointed out by valgrind

cherry-picked from @notspiff I dropped the change in CWinEventsX11Imp::CWinEventsX11Imp from original commit.
I don't think we should be messing in external sources if not necessary. If we choose to do so anyway this will need a separate commit and a patch file that goes into lib/libUPnP/patches.