check for invalid handles in dlsym/dlclose

this is wasteful and useless from a standpoint of sane programs, but
it is required by the standard, and the current requirements were
upheld with the closure of Austin Group issue #639:
http://austingroupbugs.net/view.php?id=639
fix another case of cloexec/nonblock flags not matching arch values