diff -urpN drupal-6.x-dev.org/modules/user/user.module drupal-6.x-dev/modules/user/user.module
--- drupal-6.x-dev.org/modules/user/user.module	2007-05-28 14:08:47.000000000 +0800
+++ drupal-6.x-dev/modules/user/user.module	2007-05-30 13:09:12.000000000 +0800
@@ -396,7 +396,7 @@ function user_access($string, $account =
   global $user;
   static $perm = array();
 
-  if (is_null($account)) {
+  if (is_null($account) || !isset($account->uid)) {
     $account = $user;
   }
 
@@ -1166,6 +1166,9 @@ function user_logout() {
   // Load the anonymous user
   $user = drupal_anonymous_user();
 
+  // Unlock all locked tables, and commit current transaction.
+  db_unlock_tables();
+
   drupal_goto();
 }
 
