Bug #28903 create_temp_file() doesn't honor O_TEMPORARY option (file not removed) (Unix)
Submitted: 5 Jun 2007 19:04 Modified: 28 Jul 2016 15:16
Reporter: Timothy Smith Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:all OS:Any (Not Windows)
Assigned to: CPU Architecture:Any

[5 Jun 2007 19:04] Timothy Smith
Description:
On most Unix platforms (including Linux), O_TEMPORARY is not defined.  In this case, we #define it to 0 in my_global.h.  create_temp_file() checks if (mode &O_TEMPORARY), which of course is never true.  Thus the file is not deleted automatically.

Many callers of create_temp_file() adapt to this, by calling my_delete() or unlink() directly.  However, this isn't a good solution, and doesn't work well for plugins which wish to call mysql_tmpfile().

Note that Windows biniaries (at least when compiled with Visual Studio) don't suffer from this problem.  O_TEMPORARY is defined to a non-zero value in config-win.h, and is handled explicitly in my_sopen().

How to repeat:
Set a breakpoint in create_temp_file().

Start the mysql command-line client, run a query, and then type \e (edit).  This will call create_temp_file().

Notice that mode & O_TEMPORARY is false, even though the code calls create_temp_file() with O_TEMPORARY or'd in to the mode flags.

Suggested fix:
Either define O_TEMPORARY to a non-zero value, and ensure it is handled correctly in create_temp_file() and elsewhere, or don't depend on O_TEMPORARY at all, add another flag parameter to create_temp_file(), and handle it explicitly there.
[11 Jun 2007 19:50] Timothy Smith
When this bug is fixed, please also remove the unlink() call from mysql_tmpfile() in sql_class.cc.  Also, several other callers of create_temp_file() call unlink() or my_delete(), and don't need to once this is fixed.
[19 Jun 2007 10:32] Kent Boortz
All use of create_temp_file() needs to be reviewed unless
some automatic way of handling this. One minor bug is in
"mysql.cc" and com_edit(), if an error after the
create_temp_file() call, the temporary file is not removed.
[19 Jun 2007 10:33] Magnus BlÄudd
And also mysql_upgrade
[28 Jul 2016 15:16] Paul DuBois
Posted by developer:
 
Fixed in 8.0.0.

Code cleanup. No changelog entry needed.