Skip to content

Commit

Permalink
-- Suppress the GetPlug function causing memory leak
Browse files Browse the repository at this point in the history
  modified:   storage/connect/ha_connect.h
  modified:   storage/connect/ha_connect.cc

-- Trace work storage allocation and freeing in DEVELOPMENT mode
   (Fix a compile error)
  modified:   storage/connect/plugutil.cpp
  • Loading branch information
Buggynours committed Jul 21, 2017
1 parent 6fdd5cd commit 3329fba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
55 changes: 33 additions & 22 deletions storage/connect/ha_connect.cc
Expand Up @@ -237,7 +237,7 @@ extern "C" const char *msglang(void);

static void PopUser(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,
TABLE_SHARE *table,
Expand Down Expand Up @@ -950,11 +950,11 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp)
/****************************************************************************/
/* Get the global pointer of the user of this handler. */
/****************************************************************************/
static PGLOBAL GetPlug(THD *thd, PCONNECT& lxp)
{
lxp= GetUser(thd, lxp);
return (lxp) ? lxp->g : NULL;
} // end of GetPlug
//static PGLOBAL GetPlug(THD *thd, PCONNECT lxp)
//{
// PCONNECT nxp= GetUser(thd, lxp);
// return (nxp) ? nxp->g : NULL;
//} // end of GetPlug

/****************************************************************************/
/* Get the implied table type. */
Expand Down Expand Up @@ -1529,8 +1529,9 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
if (pcf->Datefmt) {
// Find the (max) length produced by the date format
char buf[256];
PGLOBAL g= GetPlug(table->in_use, xp);
PDTP pdtp= MakeDateFormat(g, pcf->Datefmt, false, true, 0);
// PGLOBAL g= GetPlug(table->in_use, xp);
DBUG_ASSERT(xp && xp->thdp == ha_thd());
PDTP pdtp= MakeDateFormat(xp->g, pcf->Datefmt, false, true, 0);
struct tm datm;
bzero(&datm, sizeof(datm));
datm.tm_mday= 12;
Expand Down Expand Up @@ -3868,8 +3869,10 @@ int ha_connect::index_next_same(uchar *buf, const uchar *, uint)
*/
int ha_connect::rnd_init(bool scan)
{
PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) :
(xp) ? xp->g : NULL);
//PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) :
// (xp) ? xp->g : NULL);
DBUG_ASSERT(xp && xp->thdp == ha_thd());
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::rnd_init");

// This is not tested yet
Expand Down Expand Up @@ -4064,9 +4067,10 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
tdbp->SetFilter(NULL);
rc= rnd_next(buf);
} else {
PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp);
strcpy(g->Message, "Not supported by this table type");
my_message(ER_ILLEGAL_HA, g->Message, MYF(0));
// PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp);
DBUG_ASSERT(xp && xp->thdp == ha_thd());
strcpy(xp->g->Message, "Not supported by this table type");
my_message(ER_ILLEGAL_HA, xp->g->Message, MYF(0));
rc= HA_ERR_INTERNAL_ERROR;
} // endif SetRecpos

Expand Down Expand Up @@ -4115,7 +4119,10 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos)
int ha_connect::info(uint flag)
{
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");

Expand Down Expand Up @@ -4533,7 +4540,9 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
int rc= 0;
bool chk=false, cras= false;
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");

if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
Expand Down Expand Up @@ -4595,8 +4604,10 @@ int ha_connect::external_lock(THD *thd, int lock_type)
bool xcheck=false, cras= false;
MODE newmode;
PTOS options= GetTableOptionStruct();
PGLOBAL g= GetPlug(thd, xp);
DBUG_ENTER("ha_connect::external_lock");
//PGLOBAL g= GetPlug(thd, xp);
xp= GetUser(thd, xp);
PGLOBAL g= xp->g;
DBUG_ENTER("ha_connect::external_lock");

DBUG_ASSERT(thd == current_thd);

Expand Down Expand Up @@ -5376,8 +5387,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
TABTYPE ttp= TAB_UNDEF;
PQRYRES qrp= NULL;
PCOLRES crp;
PCONNECT xp= NULL;
PGLOBAL g= GetPlug(thd, xp);
PCONNECT xp= GetUser(thd, NULL);
PGLOBAL g= xp->g;

if (!g)
return HA_ERR_INTERNAL_ERROR;
Expand Down Expand Up @@ -6130,8 +6141,8 @@ int ha_connect::create(const char *name, TABLE *table_arg,
#if defined(WITH_PARTITION_STORAGE_ENGINE)
partition_info *part_info= table_arg->part_info;
#endif // WITH_PARTITION_STORAGE_ENGINE
xp= GetUser(thd, xp);
PGLOBAL g= xp->g;
xp= GetUser(thd, xp);
PGLOBAL g= xp->g;

DBUG_ENTER("ha_connect::create");
/*
Expand Down Expand Up @@ -6719,7 +6730,7 @@ bool ha_connect::FileExists(const char *fn, bool bf)
} // end of FileExists

// Called by SameString and NoFieldOptionChange
bool ha_connect::CheckString(const char *str1, const char *str2)
bool ha_connect::CheckString(PCSZ str1, PCSZ str2)
{
bool b1= (!str1 || !*str1), b2= (!str2 || !*str2);

Expand Down
4 changes: 2 additions & 2 deletions storage/connect/ha_connect.h
Expand Up @@ -166,8 +166,8 @@ class ha_connect: public handler
~ha_connect();

// CONNECT Implementation
static bool connect_init(void);
static bool connect_end(void);
//static bool connect_init(void);
//static bool connect_end(void);
TABTYPE GetRealType(PTOS pos= NULL);
char *GetRealString(PCSZ s);
PCSZ GetStringOption(PCSZ opname, PCSZ sdef= NULL);
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/plugutil.cpp
Expand Up @@ -185,7 +185,7 @@ int PlugExit(PGLOBAL g)

if (g->Sarea) {
#if !defined(DEVELOPMENT)
if (trace) {
if (trace)
#endif
htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size);

Expand Down

0 comments on commit 3329fba

Please sign in to comment.