CMake: don't try to use bundled zlib when the system's path is in the cache

The code surrounding zlib bundling did not take into consideration
that ZLIB_LIBRARY gets cached, and assumed that FIND(ZLIB) would
always set ZLIB_FOUND, which does not hold true, as this variable
signifies that we have found the package and had to look at the
system, as its location was not cached.

Only use the bundled sources if the external zlib is neither
newly-found nor cached.
Fix some memory leaks
Create directory for symlink before creating symlink
Merge pull request #1581 from nulltoken/fix/leaks

Fix some memory leaks
Merge pull request #1582 from dmgctrl/checkout_symlink_fix

Create directory for symlink before creating symlink