Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.413
diff -u -p -r1.413 menu.inc
--- includes/menu.inc	3 Oct 2010 23:29:09 -0000	1.413
+++ includes/menu.inc	5 Oct 2010 08:34:32 -0000
@@ -2293,6 +2293,15 @@ function menu_set_active_trail($new_trai
 function menu_link_get_preferred($path = NULL) {
   $preferred_links = &drupal_static(__FUNCTION__);
 
+  // Retrieve a list of menu names, ordered by preference.
+  $menu_names = menu_get_active_menu_names();
+
+  // If there are no active menus, we can't return a valid link, so return
+  // NULL early.
+  if (empty($menu_names)) {
+    return NULL;
+  }
+
   if (!isset($path)) {
     $path = $_GET['q'];
   }
@@ -2319,9 +2328,6 @@ function menu_link_get_preferred($path =
       $path_candidates[$tab_root['path']] = $tab_root['path'];
     }
 
-    // Retrieve a list of menu names, ordered by preference.
-    $menu_names = menu_get_active_menu_names();
-
     $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
     $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
     $query->fields('ml');
