Fix crash bug in regdb_close() when called with no ref count.