Bug #36091 Fix for bug #31781 is broken in 5.1/6.0
Submitted: 15 Apr 2008 12:41 Modified: 18 Apr 2008 8:59
Reporter: Alexey Kopytov Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.1+ OS:Windows
Assigned to: Alexey Kopytov CPU Architecture:Any

[15 Apr 2008 12:41] Alexey Kopytov
Description:
Found by Guilhem, quoting his email:

"
In 6.0 there is:

kaa	1.13.2.2	  /*
kaa	1.13.2.2	    my_register_filename() may fail on some platforms even if the call to
kaa	1.13.2.2	    *open() above succeeds. In this case, don't leave the stale file because
kaa	1.13.2.2	    callers assume the file to not exist if my_create() fails, so they don't
kaa	1.13.2.2	    do any cleanups.
kaa	1.13.2.2	  */
kaa	1.13.2.2	  if (unlikely(fd >= 0 && rc < 0))
kaa	1.13.2.2	  {
kaa	1.13.2.2	    int tmp= my_errno;
kaa	1.13.2.2	    my_delete(FileName, MyFlags);
kaa	1.13.2.2	    my_errno= tmp;
kaa	1.13.2.2	  }
kaa	1.13.2.2	  

But, if the if() is true, and this is Windows, the my_delete() will
probably fail because the file is open (fd>=0)?
"

The reason is that prior to the following commit to 5.1, my_register_filename() would call my_close() before returning the "out of files" error on Windows (so my_delete() in the code above would succeed): http://lists.mysql.com/commits/35375 

Since, after the above change, my_register_filename() does not close the file before returning the error, the fix bug #31781 is valid for 5.0 only, 5.1 and 6.0 still have that problem.

How to repeat:
Look at my_create() and my_register_filename() source in 5.1/6.0.

Suggested fix:
Fix my_create() in 5.1/6.0 so that in case my_register_filename() fails the file  is closed before calling my_delete().
[17 Apr 2008 18:04] Omer Barnir
triage: same as bug#31781 in 5.1/6.0 so setting to same values
[18 Apr 2008 8:59] Alexey Kopytov
Closing as "not a bug" after a closer look at the code. my_register_filename() does call my_close() on Windows when the number of opened files exceeds the limit. I just missed this fact when looking at the referenced commit email.