pkg check -d: Plug a memory leak
pkg check -d: Fix crash, should not close the db when reopened, it will be closed later

Fixes #814
Ad a pkgdb_downgrade_lock() to go from EXCLUSIVE to ADVISORY
pkg check -d: Fix double locking errors

Rather than lock/release in fix_deps, let the caller handle the upgrade
on the lock it already holds.

Rather than releasing the lock completely after each action just
downgrade it to ADVISORY again so that the next action can upgrade it
again.

This is mostly noticeable when passing multiple patterns to pkg-check.