Bug #12177 Database directory cannot be deleted after embedded server started.
Submitted: 26 Jul 2005 16:44 Modified: 14 Aug 2005 2:33
Reporter: Miguel Solorzano
Status: Closed
Category:libmysqld Severity:S2 (Serious)
Version:4.0.XX/4.1.XX OS:Microsoft Windows (Windows)
Assigned to: Alexey Botchkov Target Version:

[26 Jul 2005 16:44] Miguel Solorzano
Description:
If I execute this code:

#include <stdio.h>
#include <stdlib.h>
#include "my_global.h"
#include "mysql.h"
 
 static char *server_args[] = {
"this_program", /* this string is not used */
"--datadir=c:\\temp\\dbemb",
"--basedir=C:\\temp\\mysql4.0.23\\mysql-4.0.23-win",
"--skip-innodb"
};
static char *server_groups[] = {
"mysqld",
NULL
};

void main(void)
{

 int error, lastError;
 LPVOID lpMsgBuf;
 int errorCode = mysql_server_init( 4,
  server_args,
  server_groups );
  
 mysql_server_end();
 
 // sleep(60);
 
 /* change light.err for your computer_name.err */

 error = _unlink( "c:\\temp\\dbemb\\light.err" );
 lastError = GetLastError();
 
 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                lastError,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                (LPTSTR) &lpMsgBuf,
                  0,
                  NULL
                );
	
              printf("%s\n",lpMsgBuf);
                 
}

A file computername.err is created.

After mysql_server_end() some process seems to be still hanging around because neither
the database directory nor the computername.err can be deleted.
It seems that both the err file and the mysql directory is not freed until
the dll is unloaded.

How to repeat:
Compile and run the code above on Windows machine.
[27 Jul 2005 13:54] Francisco Reinaldo
Dear Alexey,

I'd like to contribute with the resolution of this bug.

After debugging the code, I noticed that the error files are created in a different way
than other log files.

freopen function is what creates this file but the clean_up function called from
mysql_server_end...

void STDCALL mysql_server_end()
{
  my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR));
  copy_arguments_ptr=0;
  clean_up(0);
  /* If library called my_init(), free memory allocated by it */
  if (!org_my_init_done)
    my_end(0);
}

...never calls fclose on this file. I believe because it was assumed that it will be
enough to close this file as the library is unloaded. May be because this file is needed
even after mysql_server_end. Since this has been logged as a bug, I assume that it is
desirable to close this file after mysql_server_end has been called.

As you probably know already the quick fix would be to add two new variables to hold the
file descriptors of this file and close them inside mysqld_server_end but I don't know
the code that well to foresee side effects.

I hope it helps.

Francisco.
[27 Jul 2005 14:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27636
[27 Jul 2005 14:30] Alexey Botchkov
Francisco
Thanks for your attention. You're right about the nature of this bug.
Above is the patch supposed to fix this. You can just apply it manually
if you don't want to wait until it's pushed.
[27 Jul 2005 15:29] Francisco Reinaldo
Alexey and Miguel,

Thanks a lot for your quick response.

Sincerely,
[27 Jul 2005 16:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27642
[27 Jul 2005 17:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27645
[4 Aug 2005 12:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27883
[8 Aug 2005 14:48] Alexey Botchkov
Pushed into 4.0.26
[14 Aug 2005 2:33] Paul DuBois
Noted in 4.0.26 changelog.