summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <marko@hundin.mysql.fi>2004-08-19 23:22:16 +0300
committerunknown <marko@hundin.mysql.fi>2004-08-19 23:22:16 +0300
commit03a20c23b320bb28a13aa6dc69c9445ff414a144 (patch)
tree4a5c8f5f9c3787f74852ba836a70bd210dd167b4
parent8c1af75515be705b69328e2ba664375fc0752470 (diff)
downloadmariadb-git-03a20c23b320bb28a13aa6dc69c9445ff414a144.tar.gz
ha_innodb.cc:
innobase_mysql_tmpfile(): call dup() and my_close() on the file returned by create_temp_file() in order to avoid memory leak caused by my_open() being paired with close() sql/ha_innodb.cc: innobase_mysql_tmpfile(): call dup() and my_close() on the file returned by create_temp_file() in order to avoid memory leak caused by my_open() being paired with close()
-rw-r--r--sql/ha_innodb.cc27
1 files changed, 24 insertions, 3 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 22ddfe779d5..3d3aca9cfd5 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -31,6 +31,7 @@ have disables the InnoDB inlining in this file. */
#include <assert.h>
#include <hash.h>
#include <myisampack.h>
+#include <mysys_err.h>
#define MAX_ULONG_BIT ((ulong) 1 << (sizeof(ulong)*8-1))
@@ -419,6 +420,7 @@ innobase_mysql_tmpfile(void)
/* out: temporary file descriptor, or < 0 on error */
{
char filename[FN_REFLEN];
+ int fd2 = -1;
File fd = create_temp_file(filename, NullS, "ib",
#ifdef __WIN__
O_BINARY | O_TRUNC | O_SEQUENTIAL |
@@ -426,12 +428,31 @@ innobase_mysql_tmpfile(void)
#endif /* __WIN__ */
O_CREAT | O_EXCL | O_RDWR,
MYF(MY_WME));
-#ifndef __WIN__
if (fd >= 0) {
+#ifndef __WIN__
+ /* On Windows, open files cannot be removed, but files can be
+ created with the O_TEMPORARY flag to the same effect
+ ("delete on close"). */
unlink(filename);
- }
#endif /* !__WIN__ */
- return(fd);
+ /* Copy the file descriptor, so that the additional resources
+ allocated by create_temp_file() can be freed by invoking
+ my_close().
+
+ Because the file descriptor returned by this function
+ will be passed to fdopen(), it will be closed by invoking
+ fclose(), which in turn will invoke close() instead of
+ my_close(). */
+ fd2 = dup(fd);
+ if (fd2 < 0) {
+ DBUG_PRINT("error",("Got error %d on dup",fd2));
+ my_errno=errno;
+ my_error(EE_OUT_OF_FILERESOURCES,
+ MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
+ }
+ my_close(fd, MYF(MY_WME));
+ }
+ return(fd2);
}
/*************************************************************************