MDEV-23097 heap-use-after-free in mysqlimport

mysqlimport starts many worker threads. when one of the worker
encounters an error, it frees global memory and calls exit().

it suppresses memory leak detector, because, as the comment says
"dirty exit, some threads are still running", indeed, it cannot
free the memory from other threads.

but precisely because some threads are still running, they
might use this global memory, so it cannot be freed.

fix: if we know that some threads are still running and accept
that we cannot free all memory anyway, let's not free global
allocations either
This commit is contained in:
Sergei Golubchik 2022-08-02 11:42:20 +02:00
parent 92b0a367aa
commit 07a670b884

View File

@ -524,16 +524,18 @@ static void safe_exit(int error, MYSQL *mysql)
if (mysql)
mysql_close(mysql);
mysql_library_end();
#ifdef HAVE_SMEM
my_free(shared_memory_base_name);
#endif
free_defaults(argv_to_free);
my_free(opt_password);
if (error)
sf_leaking_memory= 1; /* dirty exit, some threads are still running */
else
{
mysql_library_end();
#ifdef HAVE_SMEM
my_free(shared_memory_base_name);
#endif
free_defaults(argv_to_free);
my_free(opt_password);
my_end(my_end_arg); /* clean exit */
}
exit(error);
}