fixed: some issues pointed out by valgrind

cherry-picked from @notspiff I dropped the change in CWinEventsX11Imp::CWinEventsX11Imp from original commit.
This looks odd.  If entry->d_name is NULL, then strcmp has every right to blow up (thus, condition should be first).  Is it supposed to be checking if entry->d_name is empty?  i.e. is it supposed to be `!*entry->d_name` ?