Skip to content

Commit 83f83ba

Browse files
BUG#21368299 - SERVER CRASH AT SHUTDOWN AFTER PORT CLASH DETECTED.
MySQLD server crashes when the server is started with the port number of an existing server. Due to port clash, initialization of the acceptor object fails and the instantiated acceptor object is deleted. During cleanup on shutdown, the acceptor object is again freed. This results in corruption of the heap and thereby resulting in a crash. The fix is to free the acceptor object as part of cleanup during shutdown. Also reset all listener objects to NULL after free and close the socket listener if the listener is not closed when the socket listener is undergoing destruction.
1 parent bdfd437 commit 83f83ba

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

sql/conn_handler/socket_connection.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,5 @@ void Mysqld_socket_listener::close_listener()
10011001
}
10021002
#endif
10031003

1004-
if (!m_socket_map.empty())
1005-
m_socket_map.clear();
1004+
m_socket_map.clear();
10061005
}

sql/conn_handler/socket_connection.h

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ class Mysqld_socket_listener
171171
Close the listener.
172172
*/
173173
void close_listener();
174+
175+
~Mysqld_socket_listener()
176+
{
177+
if (!m_socket_map.empty())
178+
close_listener();
179+
}
174180
};
175181

176182
#endif // SOCKET_CONNECTION_INCLUDED.

sql/mysqld.cc

+7-13
Original file line numberDiff line numberDiff line change
@@ -1739,14 +1739,12 @@ static bool network_init(void)
17391739
if (mysqld_socket_acceptor == NULL)
17401740
{
17411741
delete mysqld_socket_listener;
1742+
mysqld_socket_listener= NULL;
17421743
return true;
17431744
}
17441745

17451746
if (mysqld_socket_acceptor->init_connection_acceptor())
1746-
{
1747-
delete mysqld_socket_acceptor;
1748-
return true;
1749-
}
1747+
return true; // mysqld_socket_acceptor would be freed in unireg_abort.
17501748

17511749
if (report_port == 0)
17521750
report_port= mysqld_port;
@@ -1770,14 +1768,12 @@ static bool network_init(void)
17701768
if (named_pipe_acceptor == NULL)
17711769
{
17721770
delete named_pipe_listener;
1771+
named_pipe_listener= NULL;
17731772
return true;
17741773
}
17751774

17761775
if (named_pipe_acceptor->init_connection_acceptor())
1777-
{
1778-
delete named_pipe_acceptor;
1779-
return true;
1780-
}
1776+
return true; // named_pipe_acceptor would be freed in unireg_abort.
17811777
}
17821778

17831779
// Setup shared_memory acceptor
@@ -1794,15 +1790,13 @@ static bool network_init(void)
17941790
new (std::nothrow) Connection_acceptor<Shared_mem_listener>(shared_mem_listener);
17951791
if (shared_mem_acceptor == NULL)
17961792
{
1797-
delete shared_mem_acceptor;
1793+
delete shared_mem_listener;
1794+
shared_mem_listener= NULL;
17981795
return true;
17991796
}
18001797

18011798
if (shared_mem_acceptor->init_connection_acceptor())
1802-
{
1803-
delete shared_mem_acceptor;
1804-
return true;
1805-
}
1799+
return true; // shared_mem_acceptor would be freed in unireg_abort.
18061800
}
18071801
#endif // _WIN32
18081802
return false;

0 commit comments

Comments
 (0)