Add code to deallocate "pendingOpenFiles" when it is no longer needed.

Fix mysterious link error by fiddling with 'extern' tags.

Provide a more robust implementation of findTargetWindow: only choose a window that is an appshell window.