Commit 162eadbe authored by unknown's avatar unknown

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:
  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.
parent c8885dfb
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
File my_create(const char *FileName, int CreateFlags, int access_flags, File my_create(const char *FileName, int CreateFlags, int access_flags,
myf MyFlags) myf MyFlags)
{ {
int fd; int fd, rc;
DBUG_ENTER("my_create"); DBUG_ENTER("my_create");
DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %d", DBUG_PRINT("my",("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %d",
FileName, CreateFlags, access_flags, MyFlags)); FileName, CreateFlags, access_flags, MyFlags));
...@@ -60,6 +60,20 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, ...@@ -60,6 +60,20 @@ File my_create(const char *FileName, int CreateFlags, int access_flags,
fd = open(FileName, access_flags); fd = open(FileName, access_flags);
#endif #endif
DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_CREATE, rc= my_register_filename(fd, FileName, FILE_BY_CREATE,
EE_CANTCREATEFILE, MyFlags)); 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;
}
DBUG_RETURN(rc);
} /* my_create */ } /* my_create */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment