From a35b48632363dbc13edf4ca6d694a630909cf92e Mon Sep 17 00:00:00 2001
From: Michael Widenius <monty@mysql.com>
Date: Mon, 19 Jul 2010 21:53:28 +0300
Subject: [PATCH] Fixed compiler and valgrind warnings

mysql-test/valgrind.supp:
  Added suppression for memory leak in dlsym() on work-amd64
plugin/auth/auth_socket.c:
  Fixed compiler warning (wrong macro usage)
storage/example/ha_example.cc:
  Fixed compiler warnings
storage/sphinx/ha_sphinx.cc:
  Fixed compiler warnings
---
 mysql-test/valgrind.supp      |  9 +++++++++
 plugin/auth/auth_socket.c     |  2 +-
 sql/sql_acl.cc                |  2 ++
 storage/example/ha_example.cc |  5 ++++-
 storage/sphinx/ha_sphinx.cc   | 34 +++++++++++++++++-----------------
 5 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp
index 0abe78bc140..8ba27c44567 100644
--- a/mysql-test/valgrind.supp
+++ b/mysql-test/valgrind.supp
@@ -539,6 +539,15 @@
    fun:_Unwind_ForcedUnwind
 }
 
+{
+   dlsym memory loss from plugin
+   Memcheck:Leak
+   fun:malloc
+   fun:_dl_signal_error
+   fun:_dl_signal_error
+   fun:_dl_lookup_symbol_x
+}
+
 #
 # Reading wrong addresses on SuSe Linux 10.3 32 bit
 #
diff --git a/plugin/auth/auth_socket.c b/plugin/auth/auth_socket.c
index 6694816dd22..cc406dac331 100644
--- a/plugin/auth/auth_socket.c
+++ b/plugin/auth/auth_socket.c
@@ -115,5 +115,5 @@ maria_declare_plugin(socket_auth)
   "1.0",
   MariaDB_PLUGIN_MATURITY_BETA
 }
-mysql_declare_plugin_end;
+maria_declare_plugin_end;
 
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 3f4400b4687..811ec614f1d 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -162,7 +162,9 @@ static LEX_STRING old_password_plugin_name= {
 LEX_STRING *default_auth_plugin_name= &native_password_plugin_name;
 
 static plugin_ref native_password_plugin;
+#ifndef EMBEDDED_LIBRARY
 static plugin_ref old_password_plugin;
+#endif
 
 /* Classes */
 
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index 6b9725dfde4..5ad6a45a744 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -367,8 +367,10 @@ int ha_example::open(const char *name, int mode, uint test_if_locked)
     DBUG_RETURN(1);
   thr_lock_data_init(&share->lock,&lock,NULL);
 
+#ifndef DBUG_OFF
   example_table_options_struct *options=
     (example_table_options_struct *)table->s->option_struct;
+#endif
 
   DBUG_ASSERT(options);
   DBUG_PRINT("info", ("strparam: '%-.64s'  ullparam: %llu  enumparam: %u  "\
@@ -896,6 +898,7 @@ ha_rows ha_example::records_in_range(uint inx, key_range *min_key,
 int ha_example::create(const char *name, TABLE *table_arg,
                        HA_CREATE_INFO *create_info)
 {
+#ifndef DBUG_OFF
   example_table_options_struct *options=
     (example_table_options_struct *)table_arg->s->option_struct;
   DBUG_ENTER("ha_example::create");
@@ -918,10 +921,10 @@ int ha_example::create(const char *name, TABLE *table_arg,
                          (field_options->compex_param_to_parse_it_in_engine ?
                           field_options->compex_param_to_parse_it_in_engine :
                           "<NULL>")));
-
   }
 
   DBUG_RETURN(0);
+#endif
 }
 
 
diff --git a/storage/sphinx/ha_sphinx.cc b/storage/sphinx/ha_sphinx.cc
index 057cec29d2d..c66c1344138 100644
--- a/storage/sphinx/ha_sphinx.cc
+++ b/storage/sphinx/ha_sphinx.cc
@@ -972,8 +972,8 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
 	}
 
 	char * sScheme = NULL;
-	char * sHost = SPHINXSE_DEFAULT_HOST;
-	char * sIndex = SPHINXSE_DEFAULT_INDEX;
+	char * sHost = (char*) SPHINXSE_DEFAULT_HOST;
+	char * sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
 	int iPort = SPHINXSE_DEFAULT_PORT;
 
 	bool bOk = true;
@@ -993,12 +993,12 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
 			// unix-domain socket
 			iPort = 0;
 			if (!( sIndex = strrchr ( sHost, ':' ) ))
-				sIndex = SPHINXSE_DEFAULT_INDEX;
+                                sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
 			else
 			{
 				*sIndex++ = '\0';
 				if ( !*sIndex )
-					sIndex = SPHINXSE_DEFAULT_INDEX;
+                                  	sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
 			}
 			bOk = true;
 			break;
@@ -1018,11 +1018,11 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
 				if ( sIndex )
 					*sIndex++ = '\0'; 
 				else
-					sIndex = SPHINXSE_DEFAULT_INDEX;
+                                  	sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
 
 				iPort = atoi(sPort);
 				if ( !iPort )
-					iPort = SPHINXSE_DEFAULT_PORT;
+                                  	iPort = SPHINXSE_DEFAULT_PORT;
 			}
 		} else
 		{
@@ -1030,7 +1030,7 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
 			if ( sIndex )
 				*sIndex++ = '\0';
 			else
-				sIndex = SPHINXSE_DEFAULT_INDEX;
+                          	sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
 		}
 
 		bOk = true;
@@ -1150,37 +1150,37 @@ static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table,
 CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex )
 	: m_sHost ( "" )
 	, m_iPort ( 0 )
-	, m_sIndex ( sIndex ? sIndex : "*" )
+	, m_sIndex ( sIndex ? sIndex : (char*) "*" )
 	, m_iOffset ( 0 )
 	, m_iLimit ( 20 )
 	, m_bQuery ( false )
-	, m_sQuery ( "" )
+	, m_sQuery ( (char*) "" )
 	, m_pWeights ( NULL )
 	, m_iWeights ( 0 )
 	, m_eMode ( SPH_MATCH_ALL )
 	, m_eRanker ( SPH_RANK_PROXIMITY_BM25 )
 	, m_eSort ( SPH_SORT_RELEVANCE )
-	, m_sSortBy ( "" )
+	, m_sSortBy ( (char*) "" )
 	, m_iMaxMatches ( 1000 )
 	, m_iMaxQueryTime ( 0 )
 	, m_iMinID ( 0 )
 	, m_iMaxID ( 0 )
 	, m_iFilters ( 0 )
 	, m_eGroupFunc ( SPH_GROUPBY_DAY )
-	, m_sGroupBy ( "" )
-	, m_sGroupSortBy ( "@group desc" )
+	, m_sGroupBy ( (char*) "" )
+	, m_sGroupSortBy ( (char*) "@group desc" )
 	, m_iCutoff ( 0 )
 	, m_iRetryCount ( 0 )
 	, m_iRetryDelay ( 0 )
-	, m_sGroupDistinct ( "" )
+	, m_sGroupDistinct ( (char*) "" )
 	, m_iIndexWeights ( 0 )
 	, m_iFieldWeights ( 0 )
 	, m_bGeoAnchor ( false )
-	, m_sGeoLatAttr ( "" )
-	, m_sGeoLongAttr ( "" )
+	, m_sGeoLatAttr ( (char*) "" )
+	, m_sGeoLongAttr ( (char*) "" )
 	, m_fGeoLatitude ( 0.0f )
 	, m_fGeoLongitude ( 0.0f )
-	, m_sComment ( "" )
+	, m_sComment ( (char*) "" )
 
 	, m_pBuf ( NULL )
 	, m_pCur ( NULL )
@@ -1622,7 +1622,7 @@ bool CSphSEQuery::ParseField ( char * sField )
 				{ "float",		SPH_ATTR_FLOAT },
 				{ "bigint",		SPH_ATTR_BIGINT }
 			};
-			for ( int i=0; i<sizeof(dAttrTypes)/sizeof(*dAttrTypes); i++ )
+			for ( uint i=0; i<sizeof(dAttrTypes)/sizeof(*dAttrTypes); i++ )
 				if ( !strncmp( sType, dAttrTypes[i].m_sName, sRest - sType ) )
 			{
 				iType = dAttrTypes[i].m_iType;
-- 
2.30.9