From 03a20c23b320bb28a13aa6dc69c9445ff414a144 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Aug 2004 23:22:16 +0300 Subject: 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() --- sql/ha_innodb.cc | 27 ++++++++++++++++++++++++--- 1 file 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 #include #include +#include #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); } /************************************************************************* -- cgit v1.2.1