Skip to content

Commit 07a670b

Browse files
committed
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
1 parent 92b0a36 commit 07a670b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

client/mysqlimport.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,18 @@ static void safe_exit(int error, MYSQL *mysql)
524524
if (mysql)
525525
mysql_close(mysql);
526526

527-
mysql_library_end();
528-
#ifdef HAVE_SMEM
529-
my_free(shared_memory_base_name);
530-
#endif
531-
free_defaults(argv_to_free);
532-
my_free(opt_password);
533527
if (error)
534528
sf_leaking_memory= 1; /* dirty exit, some threads are still running */
535529
else
530+
{
531+
mysql_library_end();
532+
#ifdef HAVE_SMEM
533+
my_free(shared_memory_base_name);
534+
#endif
535+
free_defaults(argv_to_free);
536+
my_free(opt_password);
536537
my_end(my_end_arg); /* clean exit */
538+
}
537539
exit(error);
538540
}
539541

0 commit comments

Comments
 (0)