List:Commits« Previous MessageNext Message »
From:Narayanan V Date:April 27 2009 8:24am
Subject:bzr commit into mysql-5.1-bugteam branch (v.narayanan:2872) Bug#43572
View as plain text  
#At file:///export/home/log/Narayanan/mysql_checkouts_bazaar/5.1_main_repository/mysql-5.1-bugteam-43572-1/ based on revid:patrick.crews@stripped

 2872 Narayanan V	2009-04-27
      Bug#43572 Handle failures from hash_init
      
      calls to hash_init ignore the return value. 
      This call can fail and the callers must deal
      with that.
      
      The current patch fixes instances of hash_init
      usages which ignore the return value.

    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/ha_partition.cc
      sql/hash_filo.h
      sql/item_func.cc
      sql/repl_failsafe.cc
      sql/rpl_filter.cc
      sql/rpl_tblmap.cc
      sql/sql_acl.cc
      sql/sql_cache.cc
      sql/sql_class.cc
      sql/sql_connect.cc
      sql/sql_db.cc
      storage/blackhole/ha_blackhole.cc
      storage/csv/ha_tina.cc
      storage/example/ha_example.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2008-10-23 19:27:09 +0000
+++ b/sql/ha_ndbcluster.cc	2009-04-27 08:24:33 +0000
@@ -339,8 +339,12 @@ Thd_ndb::Thd_ndb()
   m_error_code= 0;
   query_state&= NDB_QUERY_NORMAL;
   options= 0;
-  (void) hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
-                   (hash_get_key)thd_ndb_share_get_key, 0, 0);
+  if (hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
+                   (hash_get_key)thd_ndb_share_get_key, 0, 0))
+  {
+    hash_init(&open_tables, &my_charset_bin, 0, 0, 0,
+                       (hash_get_key)thd_ndb_share_get_key, 0, 0);
+  }
 }
 
 Thd_ndb::~Thd_ndb()
@@ -7420,8 +7424,12 @@ static int ndbcluster_init(void *p)
     goto ndbcluster_init_error;
   }
   
-  (void) hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) ndbcluster_get_key,0,0);
+  if (hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
+                   (hash_get_key) ndbcluster_get_key,0,0))
+  {
+    DBUG_PRINT("error", ("Failed to init HASH ndb_tables"));
+    goto ndbcluster_init_error;
+  }
 #ifdef HAVE_NDB_BINLOG
   /* start the ndb injector thread */
   if (ndbcluster_binlog_start())

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2008-04-09 16:42:05 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2009-04-27 08:24:33 +0000
@@ -3713,8 +3713,12 @@ pthread_handler_t ndb_binlog_thread_func
   }
 
   /* init hash for schema object distribution */
-  (void) hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
-                   (hash_get_key)ndb_schema_objects_get_key, 0, 0);
+  if (hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
+                   (hash_get_key)ndb_schema_objects_get_key, 0, 0))
+  {
+     sql_print_error("NDB Binlog: error initializing hash for schema object distribution");
+     goto err;
+  }
 
   /*
     Expose global reference to our ndb object.

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2009-02-20 15:56:32 +0000
+++ b/sql/ha_partition.cc	2009-04-27 08:24:33 +0000
@@ -6382,8 +6382,12 @@ static PARTITION_SHARE *get_share(const 
     {
       partition_init++;
       VOID(pthread_mutex_init(&partition_mutex, MY_MUTEX_INIT_FAST));
-      (void) hash_init(&partition_open_tables, system_charset_info, 32, 0, 0,
-		       (hash_get_key) partition_get_key, 0, 0);
+      if (hash_init(&partition_open_tables, system_charset_info, 32, 0, 0,
+		       (hash_get_key) partition_get_key, 0, 0))
+      {
+        pthread_mutex_unlock(&LOCK_mysql_create_db);
+        return NULL;
+      }
     }
     pthread_mutex_unlock(&LOCK_mysql_create_db);
   }

=== modified file 'sql/hash_filo.h'
--- a/sql/hash_filo.h	2007-05-10 09:59:39 +0000
+++ b/sql/hash_filo.h	2009-04-27 08:24:33 +0000
@@ -77,8 +77,12 @@ public:
     if (!locked)
       (void) pthread_mutex_lock(&lock);
     (void) hash_free(&cache);
-    (void) hash_init(&cache,hash_charset,size,key_offset, 
-    		     key_length, get_key, free_element,0);
+    if (hash_init(&cache,hash_charset,size,key_offset, 
+    		     key_length, get_key, free_element,0))
+    {
+      hash_init(&cache,hash_charset,0,0,
+               0, get_key, free_element,0);
+    }
     if (!locked)
       (void) pthread_mutex_unlock(&lock);
     first_link=last_link=0;

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2009-04-23 07:50:34 +0000
+++ b/sql/item_func.cc	2009-04-27 08:24:33 +0000
@@ -3302,9 +3302,9 @@ static bool item_user_lock_inited= 0;
 void item_user_lock_init(void)
 {
   pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW);
-  hash_init(&hash_user_locks,system_charset_info,
-	    16,0,0,(hash_get_key) ull_get_key,NULL,0);
-  item_user_lock_inited= 1;
+  if (!hash_init(&hash_user_locks,system_charset_info,
+	    16,0,0,(hash_get_key) ull_get_key,NULL,0))
+    item_user_lock_inited= 1;
 }
 
 void item_user_lock_free(void)

=== modified file 'sql/repl_failsafe.cc'
--- a/sql/repl_failsafe.cc	2009-01-09 12:49:24 +0000
+++ b/sql/repl_failsafe.cc	2009-04-27 08:24:33 +0000
@@ -221,8 +221,10 @@ extern "C" void slave_info_free(void *s)
 
 void init_slave_list()
 {
-  hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
-	    (hash_get_key) slave_list_key, (hash_free_key) slave_info_free, 0);
+  if (hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
+	    (hash_get_key) slave_list_key, (hash_free_key) slave_info_free, 0))
+    hash_init(&slave_list, system_charset_info, 0, 0, 0,
+            (hash_get_key) slave_list_key, (hash_free_key) slave_info_free, 0);
   pthread_mutex_init(&LOCK_slave_list, MY_MUTEX_INIT_FAST);
 }
 

=== modified file 'sql/rpl_filter.cc'
--- a/sql/rpl_filter.cc	2007-08-13 13:11:25 +0000
+++ b/sql/rpl_filter.cc	2009-04-27 08:24:33 +0000
@@ -386,8 +386,11 @@ void free_table_ent(void* a)
 void 
 Rpl_filter::init_table_rule_hash(HASH* h, bool* h_inited)
 {
-  hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0,
-	    get_table_key, free_table_ent, 0);
+  if (hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0,
+	    get_table_key, free_table_ent, 0))
+  {
+    *h_inited = 0;
+  }
   *h_inited = 1;
 }
 

=== modified file 'sql/rpl_tblmap.cc'
--- a/sql/rpl_tblmap.cc	2008-08-20 14:06:31 +0000
+++ b/sql/rpl_tblmap.cc	2009-04-27 08:24:33 +0000
@@ -34,12 +34,16 @@ table_mapping::table_mapping()
     No "free_element" function for entries passed here, as the entries are
     allocated in a MEM_ROOT (freed as a whole in the destructor), they cannot
     be freed one by one.
-    Note that below we don't test if hash_init() succeeded. This constructor
-    is called at startup only.
+    This constructor is called at startup only.
+    If hash_init fails with TABLE_ID_HASH_SIZE try a 0 size allocation
   */
-  (void) hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE,
+  if (hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE,
 		   offsetof(entry,table_id),sizeof(ulong),
-		   0,0,0);
+		   0,0,0))
+  {
+    hash_init(&m_table_ids,&my_charset_bin,0,
+               0,0,0,0,0);
+  }
   /* We don't preallocate any block, this is consistent with m_free=0 above */
   init_alloc_root(&m_mem_root, TABLE_ID_HASH_SIZE*sizeof(entry), 0);
 }

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-04-08 23:42:51 +0000
+++ b/sql/sql_acl.cc	2009-04-27 08:24:33 +0000
@@ -1422,8 +1422,12 @@ static void init_check_host(void)
   DBUG_ENTER("init_check_host");
   VOID(my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip),
 			  acl_users.elements,1));
-  VOID(hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0,
-		 (hash_get_key) check_get_key,0,0));
+  if (hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0,
+		 (hash_get_key) check_get_key,0,0))
+  {
+    hash_init(&acl_check_hosts,system_charset_info,0,0,0,
+             (hash_get_key) check_get_key,0,0);
+  }
   if (!allow_all_hosts)
   {
     for (uint i=0 ; i < acl_users.elements ; i++)

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2009-03-24 13:58:52 +0000
+++ b/sql/sql_cache.cc	2009-04-27 08:24:33 +0000
@@ -2012,8 +2012,9 @@ ulong Query_cache::init_cache()
 
   DUMP(this);
 
-  VOID(hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0,
-		 query_cache_query_get_key, 0, 0));
+  if (hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0,
+		 query_cache_query_get_key, 0, 0))
+    goto err;
 #ifndef FN_NO_CASE_SENCE
   /*
     If lower_case_table_names!=0 then db and table names are already 
@@ -2023,8 +2024,9 @@ ulong Query_cache::init_cache()
     lower_case_table_names == 0 then we should distinguish my_table
     and MY_TABLE cases and so again can use binary collation.
   */
-  VOID(hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0,
-		 query_cache_table_get_key, 0, 0));
+  if (hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0,
+		 query_cache_table_get_key, 0, 0))
+    goto err;
 #else
   /*
     On windows, OS/2, MacOS X with HFS+ or any other case insensitive
@@ -2034,10 +2036,11 @@ ulong Query_cache::init_cache()
     file system) and so should use case insensitive collation for
     comparison.
   */
-  VOID(hash_init(&tables,
+  if (hash_init(&tables,
 		 lower_case_table_names ? &my_charset_bin :
 		 files_charset_info,
-		 def_table_hash_size, 0, 0,query_cache_table_get_key, 0, 0));
+		 def_table_hash_size, 0, 0,query_cache_table_get_key, 0, 0))
+    goto err;
 #endif
 
   queries_in_cache = 0;

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-04-03 18:21:57 +0000
+++ b/sql/sql_class.cc	2009-04-27 08:24:33 +0000
@@ -642,9 +642,12 @@ THD::THD()
   profiling.set_thd(this);
 #endif
   user_connect=(USER_CONN *)0;
-  hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
+  if (hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
 	    (hash_get_key) get_var_key,
-	    (hash_free_key) free_user_var, 0);
+	    (hash_free_key) free_user_var, 0))
+        hash_init(&user_vars, system_charset_info, 0, 0, 0,
+                (hash_get_key) get_var_key,
+                        (hash_free_key) free_user_var, 0);
 
   sp_proc_cache= NULL;
   sp_func_cache= NULL;
@@ -838,9 +841,12 @@ void THD::change_user(void)
   cleanup_done= 0;
   init();
   stmt_map.reset();
-  hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
+  if (hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
 	    (hash_get_key) get_var_key,
-	    (hash_free_key) free_user_var, 0);
+	    (hash_free_key) free_user_var, 0))
+    hash_init(&user_vars, system_charset_info, 0, 0, 0,
+            (hash_get_key) get_var_key,
+                    (hash_free_key) free_user_var, 0);
   sp_cache_clear(&sp_proc_cache);
   sp_cache_clear(&sp_func_cache);
 }
@@ -2441,12 +2447,18 @@ Statement_map::Statement_map() :
     START_STMT_HASH_SIZE = 16,
     START_NAME_HASH_SIZE = 16
   };
-  hash_init(&st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0,
+  if (hash_init(&st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0,
             get_statement_id_as_hash_key,
-            delete_statement_as_hash_key, MYF(0));
-  hash_init(&names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0,
+            delete_statement_as_hash_key, MYF(0)))
+    hash_init(&st_hash, &my_charset_bin, 0, 0, 0,
+                get_statement_id_as_hash_key,
+                            delete_statement_as_hash_key, MYF(0));
+  if (hash_init(&names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0,
             (hash_get_key) get_stmt_name_hash_key,
-            NULL,MYF(0));
+            NULL,MYF(0)))
+    hash_init(&names_hash, system_charset_info, 0, 0, 0,
+                (hash_get_key) get_stmt_name_hash_key,
+                            NULL,MYF(0));
 }
 
 

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2009-02-13 16:41:47 +0000
+++ b/sql/sql_connect.cc	2009-04-27 08:24:33 +0000
@@ -516,10 +516,15 @@ extern "C" void free_user(struct user_co
 void init_max_user_conn(void)
 {
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
-  (void) hash_init(&hash_user_connections,system_charset_info,max_connections,
-		   0,0,
-		   (hash_get_key) get_key_conn, (hash_free_key) free_user,
-		   0);
+  if (hash_init(&hash_user_connections,system_charset_info,max_connections,
+		        0,0,
+		        (hash_get_key) get_key_conn, (hash_free_key) free_user,
+		        0))
+    hash_init(&hash_user_connections,system_charset_info,0,
+                    0,0,
+                    (hash_get_key) get_key_conn, (hash_free_key)
+                    free_user,
+                    0);
 #endif
 }
 

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2009-04-08 23:42:51 +0000
+++ b/sql/sql_db.cc	2009-04-27 08:24:33 +0000
@@ -261,10 +261,14 @@ void my_dbopt_cleanup(void)
 {
   rw_wrlock(&LOCK_dboptions);
   hash_free(&dboptions);
-  hash_init(&dboptions, lower_case_table_names ? 
+  if (hash_init(&dboptions, lower_case_table_names ? 
             &my_charset_bin : system_charset_info,
             32, 0, 0, (hash_get_key) dboptions_get_key,
-            free_dbopt,0);
+            free_dbopt,0))
+    hash_init(&dboptions, lower_case_table_names ?
+          &my_charset_bin : system_charset_info,
+          0, 0, 0, (hash_get_key) dboptions_get_key,
+          free_dbopt,0);
   rw_unlock(&LOCK_dboptions);
 }
 

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2008-11-10 20:21:49 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2009-04-27 08:24:33 +0000
@@ -335,9 +335,10 @@ static int blackhole_init(void *p)
   blackhole_hton->flags= HTON_CAN_RECREATE;
   
   VOID(pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST));
-  (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
+  if (hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
                    (hash_get_key) blackhole_get_key,
-                   (hash_free_key) blackhole_free_key, 0);
+                   (hash_free_key) blackhole_free_key, 0))
+    return 1;
 
   return 0;
 }

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2009-03-24 09:02:01 +0000
+++ b/storage/csv/ha_tina.cc	2009-04-27 08:24:33 +0000
@@ -110,8 +110,9 @@ static int tina_init_func(void *p)
 
   tina_hton= (handlerton *)p;
   VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST));
-  (void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) tina_get_key,0,0);
+  if (hash_init(&tina_open_tables,system_charset_info,32,0,0,
+                   (hash_get_key) tina_get_key,0,0))
+    return 1;
   tina_hton->state= SHOW_OPTION_YES;
   tina_hton->db_type= DB_TYPE_CSV_DB;
   tina_hton->create= tina_create_handler;

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2008-02-24 13:12:17 +0000
+++ b/storage/example/ha_example.cc	2009-04-27 08:24:33 +0000
@@ -132,8 +132,9 @@ static int example_init_func(void *p)
 
   example_hton= (handlerton *)p;
   VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST));
-  (void) hash_init(&example_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) example_get_key,0,0);
+  if (hash_init(&example_open_tables,system_charset_info,32,0,0,
+                   (hash_get_key) example_get_key,0,0))
+    DBUG_RETURN(1);
 
   example_hton->state=   SHOW_OPTION_YES;
   example_hton->create=  example_create_handler;


Attachment: [text/bzr-bundle] bzr/v.narayanan@sun.com-20090427082433-clkgu59isvhrg2za.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (v.narayanan:2872) Bug#43572Narayanan V27 Apr