Commit cfe3252a authored by Olivier Bertrand's avatar Olivier Bertrand

-- No suppressing of the GetPlug function. It is GetUser that can cause memory leak

   when xp is modified. The old xp must be poped or is never freed.
  modified:   storage/connect/ha_connect.cc
parent 3329fbae
...@@ -222,9 +222,7 @@ bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db, ...@@ -222,9 +222,7 @@ bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db,
PCSZ tab, PCSZ src, int port); PCSZ tab, PCSZ src, int port);
bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool); bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool);
bool ExactInfo(void); bool ExactInfo(void);
#if defined(MONGO_SUPPORT)
void mongo_init(bool); void mongo_init(bool);
#endif // MONGO_SUPPORT
USETEMP UseTemp(void); USETEMP UseTemp(void);
int GetConvSize(void); int GetConvSize(void);
TYPCONV GetTypeConv(void); TYPCONV GetTypeConv(void);
...@@ -237,7 +235,7 @@ extern "C" const char *msglang(void); ...@@ -237,7 +235,7 @@ extern "C" const char *msglang(void);
static void PopUser(PCONNECT xp); static void PopUser(PCONNECT xp);
static PCONNECT GetUser(THD *thd, PCONNECT xp); static PCONNECT GetUser(THD *thd, PCONNECT xp);
//static PGLOBAL GetPlug(THD *thd, PCONNECT lxp); static PGLOBAL GetPlug(THD *thd, PCONNECT& lxp);
static handler *connect_create_handler(handlerton *hton, static handler *connect_create_handler(handlerton *hton,
TABLE_SHARE *table, TABLE_SHARE *table,
...@@ -917,9 +915,13 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp) ...@@ -917,9 +915,13 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp)
if (!thd) if (!thd)
return NULL; return NULL;
if (xp && thd == xp->thdp) if (xp) {
if (thd == xp->thdp)
return xp; return xp;
PopUser(xp); // Avoid memory leak
} // endif xp
pthread_mutex_lock(&usrmut); pthread_mutex_lock(&usrmut);
for (xp= user_connect::to_users; xp; xp= xp->next) for (xp= user_connect::to_users; xp; xp= xp->next)
...@@ -950,11 +952,11 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp) ...@@ -950,11 +952,11 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp)
/****************************************************************************/ /****************************************************************************/
/* Get the global pointer of the user of this handler. */ /* Get the global pointer of the user of this handler. */
/****************************************************************************/ /****************************************************************************/
//static PGLOBAL GetPlug(THD *thd, PCONNECT lxp) static PGLOBAL GetPlug(THD *thd, PCONNECT& lxp)
//{ {
// PCONNECT nxp= GetUser(thd, lxp); lxp= GetUser(thd, lxp);
// return (nxp) ? nxp->g : NULL; return (lxp) ? lxp->g : NULL;
//} // end of GetPlug } // end of GetPlug
/****************************************************************************/ /****************************************************************************/
/* Get the implied table type. */ /* Get the implied table type. */
...@@ -1529,9 +1531,8 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) ...@@ -1529,9 +1531,8 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
if (pcf->Datefmt) { if (pcf->Datefmt) {
// Find the (max) length produced by the date format // Find the (max) length produced by the date format
char buf[256]; char buf[256];
// PGLOBAL g= GetPlug(table->in_use, xp); PGLOBAL g= GetPlug(table->in_use, xp);
DBUG_ASSERT(xp && xp->thdp == ha_thd()); PDTP pdtp= MakeDateFormat(g, pcf->Datefmt, false, true, 0);
PDTP pdtp= MakeDateFormat(xp->g, pcf->Datefmt, false, true, 0);
struct tm datm; struct tm datm;
bzero(&datm, sizeof(datm)); bzero(&datm, sizeof(datm));
datm.tm_mday= 12; datm.tm_mday= 12;
...@@ -3869,10 +3870,8 @@ int ha_connect::index_next_same(uchar *buf, const uchar *, uint) ...@@ -3869,10 +3870,8 @@ int ha_connect::index_next_same(uchar *buf, const uchar *, uint)
*/ */
int ha_connect::rnd_init(bool scan) int ha_connect::rnd_init(bool scan)
{ {
//PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) : PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) :
// (xp) ? xp->g : NULL); (xp) ? xp->g : NULL);
DBUG_ASSERT(xp && xp->thdp == ha_thd());
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::rnd_init"); DBUG_ENTER("ha_connect::rnd_init");
// This is not tested yet // This is not tested yet
...@@ -4067,10 +4066,9 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) ...@@ -4067,10 +4066,9 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
tdbp->SetFilter(NULL); tdbp->SetFilter(NULL);
rc= rnd_next(buf); rc= rnd_next(buf);
} else { } else {
// PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp); PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp);
DBUG_ASSERT(xp && xp->thdp == ha_thd()); strcpy(g->Message, "Not supported by this table type");
strcpy(xp->g->Message, "Not supported by this table type"); my_message(ER_ILLEGAL_HA, g->Message, MYF(0));
my_message(ER_ILLEGAL_HA, xp->g->Message, MYF(0));
rc= HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
} // endif SetRecpos } // endif SetRecpos
...@@ -4119,10 +4117,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) ...@@ -4119,10 +4117,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
int ha_connect::info(uint flag) int ha_connect::info(uint flag)
{ {
bool pure= false; bool pure= false;
//PGLOBAL g= GetPlug((table) ? table->in_use : NULL, xp); PGLOBAL g= GetPlug((table) ? table->in_use : NULL, xp);
//xp= GetUser((table) ? table->in_use : NULL, xp); // Usefull ???
DBUG_ASSERT(xp && xp->thdp == ha_thd());
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::info"); DBUG_ENTER("ha_connect::info");
...@@ -4540,9 +4535,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) ...@@ -4540,9 +4535,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
int rc= 0; int rc= 0;
bool chk=false, cras= false; bool chk=false, cras= false;
MODE newmode; MODE newmode;
//PGLOBAL g= GetPlug(thd, xp); PGLOBAL g= GetPlug(thd, xp);
xp = GetUser(thd, xp);
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::start_stmt"); DBUG_ENTER("ha_connect::start_stmt");
if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
...@@ -4604,9 +4597,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -4604,9 +4597,7 @@ int ha_connect::external_lock(THD *thd, int lock_type)
bool xcheck=false, cras= false; bool xcheck=false, cras= false;
MODE newmode; MODE newmode;
PTOS options= GetTableOptionStruct(); PTOS options= GetTableOptionStruct();
//PGLOBAL g= GetPlug(thd, xp); PGLOBAL g= GetPlug(thd, xp);
xp= GetUser(thd, xp);
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::external_lock"); DBUG_ENTER("ha_connect::external_lock");
DBUG_ASSERT(thd == current_thd); DBUG_ASSERT(thd == current_thd);
...@@ -5387,8 +5378,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5387,8 +5378,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
TABTYPE ttp= TAB_UNDEF; TABTYPE ttp= TAB_UNDEF;
PQRYRES qrp= NULL; PQRYRES qrp= NULL;
PCOLRES crp; PCOLRES crp;
PCONNECT xp= GetUser(thd, NULL); PCONNECT xp= NULL;
PGLOBAL g= xp->g; PGLOBAL g= GetPlug(thd, xp);
if (!g) if (!g)
return HA_ERR_INTERNAL_ERROR; return HA_ERR_INTERNAL_ERROR;
......
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