Index: themekey_build.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/themekey_build.inc,v
retrieving revision 1.13.2.15
diff -u -r1.13.2.15 themekey_build.inc
--- themekey_build.inc	5 Jan 2010 21:06:58 -0000	1.13.2.15
+++ themekey_build.inc	6 Jan 2010 16:16:45 -0000
@@ -352,19 +352,21 @@
   $num_childs = db_result(db_query("SELECT COUNT(*) FROM {themekey_properties} WHERE parent = %d", $id));
   if (FALSE !== $num_childs) {
     if ($num_childs > 0) {
+      db_unlock_tables();
       drupal_set_message(t('ThemeKey rule could not be deleted because it has children in the chain'), 'error');
     }
     else {
-      if (!db_query('DELETE FROM {themekey_properties} WHERE id = %d', $id)) {
+      $result = db_query('DELETE FROM {themekey_properties} WHERE id = %d', $id);
+      db_unlock_tables();
+      if (!$result) {
         drupal_set_message(t('Error while deleteing ThemeKey rule'), 'error');
       }
     }
   }
   else {
+    db_unlock_tables();
     drupal_set_message(t('Error while deleteing ThemeKey rule'), 'error');
   }
-
-  db_unlock_tables();
 }
 
 
