Bug #12850 free_charsets not called in my_init.c
Submitted: 29 Aug 2005 17:22 Modified: 23 Oct 2005 8:23
Reporter: Robert Hatcher Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.11 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[29 Aug 2005 17:22] Robert Hatcher
Description:
This is a user-written client program using MySQL 4.1.11 and MyODBC 3.51.11
all compiled from source with gcc 3.4.3.

$ cd mysql-4.1.11/mysys
$ diff my_init.c my_init.c-4.1.11
   143d142
   <   free_charsets();
 
The addition of this call properly cleans things up for later connections.

 This fix is based on info described in the MySQL bug report #7344:
   http://bugs.mysql.com/bug.php?id=7344
   http://lists.mysql.com/internals/22145

 On those pages there are fixes proposed to MySQL 4.1.10a
 in the files mysys/my_init.c, myisam/ft_stopwords.c and sql/mysqld.cc.
 It appears that the developers applied the later two, but not this one in
 creating release 4.1.11.

A check of the source code seems to indicate that this remains unfixed for 4.1.14.

$ loon -bq test_fablookup.C  # without fix
 
Successfully opened connection to: mysql:odbc://<machineip>/temp?option=1;
Successfully opened connection to: mysql:odbc://<machineip>/offline?option=1;
DbiCascader Status:-
Status   URL
  
Closed         mysql:odbc://<machineip>/temp?option=1;
Closed         mysql:odbc://<machineip>/offline?option=1;
   
Character set 'latin1' is not a compiled character set and is not specified in the '/home/minlib/minos_external/GCC_3_4/share/mysql/charsets/Index.xml' file
The following TSQL errors have occured:-
  Failed to connect to datasource: [unixODBC][MySQL][ODBC 3.51 Driver]Can't initialize character set latin1 (path: /home/minlib/minos_external/GCC_3_4/share/mysql/charsets/)
  
=W= Dbi [-1|-1] DbiConnection.cxx,v1.13:198> Failed to open a connection to: mysql:odbc://<machineip>/temp?option=1;, retrying ...
Segmentation fault
 
latin1 is indeed in the Index.xml file, but sometimes the SEGV happens without this
warning making it back.  As indicated this is because various things aren't reinitialized
and so one is dependent on previous state.

$ loon -bq test_fablookup.C # with fixed library
loon [0]
 
Successfully opened connection to: mysql:odbc://<machineip>/temp?option=1;
Successfully opened connection to: mysql:odbc://<machineip>/offline?option=1;
DbiCascader Status:-
Status   URL
  
Closed         mysql:odbc://<machineip>/temp?option=1;
Closed         mysql:odbc://<machineip>/offline?option=1;
  
[...success...]

How to repeat:
I have no trivial example of how to demonstrate this.

Suggested fix:
$ diff my_init.c my_init.c-4.1.11
   143d142
   <   free_charsets();
[31 Aug 2005 22:14] Jorge del Conde
free_charsets shouldn't be called by my_init.c .. it should be called when the server terminates.

Here is the code responsible for calling free_charsets():

libmysql.c
void STDCALL mysql_server_end()
{
<cut>
  free_charsets(); 
  mysql_client_init= org_my_init_done= 0;
#ifdef EMBEDDED_SERVER
  if (stderror_file) 
  {
    fclose(stderror_file);
    stderror_file= 0;
  }
#endif
}
[31 Aug 2005 22:38] Robert Hatcher
I respectfully disagree. What you've given is exactly what the code already looks like in libmysql.c for 4.1.14, which I've since downloaded and built, and the code still crashes UNLESS the fix I gave for my_init.c is added.  There IS a bug, somewhere...perhaps my_init.c isn't where the
free_charsets should be called, but it's got to be somewhere other than what is already there.
[31 Aug 2005 23:12] Robert Hatcher
Actually, I'm even more confused by the statement: "free_charsets shouldn't be called by my_init.c .. it should be called when the server  terminates."  I believe the message isn't coming from the server, but from the client.  You point to the function mysql_server_end() but I don't think the problem is the server.

If I run my program ("loon" which makes calls to unixODBC->MyODBC->MySQL libraries) where the my_init.c has NOT been modified, but against a database server on a wholly separate machine that HAS undergone the modification, then I get the same result of a SEGV.  

In case it matters, here's the config for my build:
  ./configure --prefix=${INSTALLATION} \
      --without-bench                  \
      --with-thread-safe-client        \
      --enable-thread-safe-client      \
      --enable-local-infile            \
      --enable-shared                  \
      --disable-static                 \
[23 Sep 2005 8:23] Valeriy Kravchuk
I've checked my_init.c in the yesterday's BK source of 4.1.15, and free_charsets still is not called there. I believe, it can cause problems, but this change was not included in the change set for the bug you had written about, and there may be reasons for it.

To be able to ask developers for additional checks we need a simple and repeatable test case, that will prove that in current code there is a problem. So, please, send a part of your ODBC code that demonstrate this bug or, at least, a description of actions it performs.
[23 Oct 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".