From: Date: March 2 2008 5:15pm Subject: bk commit into 5.0 tree (kaa:1.2609) BUG#31781 List-Archive: http://lists.mysql.com/commits/43272 X-Bug: 31781 Message-Id: <20080302161544.C58FF1D7C5@kaamos.local> Below is the list of changes that have just been committed into a local 5.0 repository of kaa. When kaa does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2008-03-02 19:15:41+03:00, kaa@kaamos.(none) +1 -0 Fix for bug #31781: multi-table UPDATE with temp-pool enabled fails with errno 17 my_create() did not perform any checks for the case when a file is successfully created by a call to open(), but the call to my_register_filename() later fails because the number of open files has exceeded the my_open_files limit. This can happen on platforms which do not have getrlimit(), and hence we do not know the real limit for open files. In such a case an error was returned to a caller although the file has actually been created. Since callers assume my_create() to return an error only when it failed to create a file, they did not perform any cleanups, leaving an 'orphaned' file on the file system. Fixed by adding a check for the above case to my_create() and ensuring the newly created file is deleted before returning an error. Creating a deterministic test case in the test suite is impossible, because the exact steps required to reproduce the above situation depend on the platform and/or environment (OS per-user limits, queries executed by previous tests, startup parameters). The patch was manually tested on Windows using examples posted in the bug report. mysys/my_create.c@stripped, 2008-03-02 19:15:40+03:00, kaa@kaamos.(none) +17 -3 Ensure that, if the call to my_register_filename() in my_create() failed, but the previous open() called succeeded, the newly created file is deleted before returning an error. diff -Nrup a/mysys/my_create.c b/mysys/my_create.c --- a/mysys/my_create.c 2006-12-23 22:04:07 +03:00 +++ b/mysys/my_create.c 2008-03-02 19:15:40 +03:00 @@ -35,7 +35,7 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, myf MyFlags) { - int fd; + int fd, rc; DBUG_ENTER("my_create"); DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %d", FileName, CreateFlags, access_flags, MyFlags)); @@ -60,6 +60,20 @@ File my_create(const char *FileName, int fd = open(FileName, access_flags); #endif - DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_CREATE, - EE_CANTCREATEFILE, MyFlags)); + rc= my_register_filename(fd, FileName, FILE_BY_CREATE, + EE_CANTCREATEFILE, MyFlags); + /* + my_register_filename() may fail on some platforms even if the call to + *open() above succeeds. In this case, don't leave the stale file because + callers assume the file to not exist if my_create() fails, so they don't + do any cleanups. + */ + if (unlikely(fd >= 0 && rc < 0)) + { + int tmp= my_errno; + my_delete(FileName, MyFlags); + my_errno= tmp; + } + + return rc; } /* my_create */