Bug #2570 Random changes in decimal point
Submitted: 29 Jan 2004 19:53 Modified: 6 Dec 2006 21:07
Reporter: Boyd Gerber Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:3.51.06/7 OS:Microsoft Windows (windows)
Assigned to: Jess Balint CPU Architecture:Any
Tags: Contribution

[29 Jan 2004 19:53] Boyd Gerber
Description:
'm using MyODBC 3.51.06, unixODBC 2.2.3, MySQL 3.23.58 and Conectiva
Linux 8.0.

Random changes of the decimal point occur when 2 environment handles are
used.

SQLAllocHandle() calls my_SQLAllocEnv() that calls myodbc_init().
myodbc_init() sets myodbc_inited=1 and alloc default_locale.

Calling SQLAllocHandle() again, myodbc_init verify myodbc_inited and
return.

Now, SQLFreeHandle() calls my_SQLFreeEnv() hat calls myodbc_end().
myodbc_end() verify myodbc_inited, and free default_locale.

If SQLGetData(), SQLFetch() or functions that call insert_params() are
called with the first handle, then freed default_locale is used.

I'm sending a patch adding a counter in myodbc_init()/end().

How to repeat:
A patch was sent to monty@mysql.com and venu@mysql.com

Suggested fix:
See above need patch from monty or venu
[30 Jan 2004 7:53] Boyd Gerber
Here is the patch.

Index: driver/dll.c
===================================================================
RCS file: /cvsroot/MyODBC/driver/dll.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 dll.c
--- driver/dll.c        2004/01/29 13:17:26     1.1.1.1
+++ driver/dll.c        2004/01/29 17:54:43
@@ -33,7 +33,7 @@
 char *default_locale, *decimal_point, *thousands_sep;
 uint decimal_point_length,thousands_sep_length;
 static my_bool myodbc_inited=0;
-
+static int myodbc_init_counter=0;
 /*
   @type    : myodbc3 internal
   @purpose : initializations
@@ -42,8 +42,12 @@
 void myodbc_init(void)
 {
   if (myodbc_inited)
+  {
+    myodbc_init_counter++;
     return;
+  }
   myodbc_inited=1;
+  myodbc_init_counter=1;
   my_init();
   {
     struct lconv *tmp;
@@ -80,14 +84,18 @@
 {
  if (myodbc_inited)
  {
-   myodbc_inited=0;
-   my_free(decimal_point,MYF(0));
-   my_free(default_locale,MYF(0));
-   my_free(thousands_sep,MYF(0));
+   myodbc_init_counter--;
+   if (myodbc_init_counter==0)
+   {
+     myodbc_inited=0;
+     my_free(decimal_point,MYF(0));
+     my_free(default_locale,MYF(0));
+     my_free(thousands_sep,MYF(0));
+   myodbc_init_counter--;
+   if (myodbc_init_counter==0)
+   {
+     myodbc_inited=0;
+     my_free(decimal_point,MYF(0));
+     my_free(default_locale,MYF(0));
+     my_free(thousands_sep,MYF(0));
 #ifdef NOT_YET_USED
-   mysql_server_end();
+     mysql_server_end();
 #endif
-   my_end(0);
+     my_end(0);
+   }
  }
 }
[6 Dec 2006 21:05] Jess Balint
Test Case

Attachment: mysql_bug_2570_t1.cpp (plain/text, text), 2.63 KiB.

[6 Dec 2006 21:07] Jess Balint
Cannot repeat on Windows w/3.51.12. See attached test case. I have not attempted to look into the driver code in regards to this issue.
[6 Dec 2006 21:23] Mark Matthews
Note that we added reference counting for initialization as a fix for a different bug, but it ends up taking care of this one too.