Commit 8ca75559 authored by unknown's avatar unknown

fixed memory-leak in case of connect failure

parent c8510bf8
...@@ -1488,28 +1488,30 @@ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) ...@@ -1488,28 +1488,30 @@ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc)
{ {
NdbMgmHandle h; NdbMgmHandle h;
struct ndb_mgm_reply mgm_reply; struct ndb_mgm_reply mgm_reply;
char *cs, c[100];
bool d=false;
h= ndb_mgm_create_handle(); h= ndb_mgm_create_handle();
if(strlen(sc->get_server_name())>80) /**
* Set connectstring
*/
{ {
/* char c[100];
* server name is long. malloc enough for it and the port number char *cs= &c[0];
*/ int len= strlen(sc->get_server_name())+20;
cs= (char*)malloc((strlen(sc->get_server_name())+20)*sizeof(char)); if( len > sizeof(c) )
if(!cs) {
return NDB_INVALID_SOCKET; /*
d= true; * server name is long. malloc enough for it and the port number
*/
cs= (char*)malloc(len*sizeof(char));
if(!cs)
return NDB_INVALID_SOCKET;
}
snprintf(cs,len,"%s:%u",sc->get_server_name(),sc->get_port());
ndb_mgm_set_connectstring(h, cs);
if(cs != &c[0])
free(cs);
} }
else
cs = &c[0];
snprintf(cs,(d)?strlen(sc->get_server_name()+20):sizeof(c),
"%s:%u",sc->get_server_name(),sc->get_port());
ndb_mgm_set_connectstring(h, cs);
if(ndb_mgm_connect(h, 0, 0, 0)<0) if(ndb_mgm_connect(h, 0, 0, 0)<0)
return NDB_INVALID_SOCKET; return NDB_INVALID_SOCKET;
...@@ -1521,8 +1523,6 @@ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc) ...@@ -1521,8 +1523,6 @@ NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc)
CFG_CONNECTION_SERVER_PORT, CFG_CONNECTION_SERVER_PORT,
m_transporter_interface[i].m_s_service_port, m_transporter_interface[i].m_s_service_port,
&mgm_reply); &mgm_reply);
if(d)
free(cs);
return ndb_mgm_convert_to_transporter(h); return ndb_mgm_convert_to_transporter(h);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment