Re: I need help, about c++ pointer

From: Quan Zongliang <quanzongliang(at)gmail(dot)com>
To: pgadmin-support(at)postgresql(dot)org
Subject: Re: I need help, about c++ pointer
Date: 2009-07-15 23:01:12
Message-ID: 20090716073906.4DC8.4125B4E5@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

Another pointer error.

ponters are created by:
int tablecount = 0;
SQLWCHAR **tabledata, ***tablelist;

while (true)
{
sqlrc = SQLFetch(tableshstmt);
if (sqlrc != SQL_SUCCESS && sqlrc != SQL_SUCCESS_WITH_INFO)
break;

if (m_dsnmaxcatnamelen)
{
SQLGetData(tableshstmt, 1, SQL_C_WCHAR, catname, sizeof(SQLWCHAR)*m_dsnmaxcatnamelen, NULL);
catnameptr = new SQLWCHAR[wcslen(catname)+1];
wcscpy(catnameptr, catname);
}
else
catnameptr = NULL;

if (m_dsnmaxschemnamelen)
{
SQLGetData(tableshstmt, 2, SQL_C_WCHAR, schemname, sizeof(SQLWCHAR)*m_dsnmaxschemnamelen, NULL);
schemnameptr = new SQLWCHAR[wcslen(schemname)+1];
wcscpy(schemnameptr, schemname);
}
else
schemnameptr = NULL;

SQLGetData(tableshstmt, 3, SQL_C_WCHAR, tablename, sizeof(SQLWCHAR)*m_dsnmaxtablenamelen, NULL);
tablenameptr = new SQLWCHAR[wcslen(tablename)+1];
wcscpy(tablenameptr, tablename);

tabledata = new SQLWCHAR *[3];
tabledata[0] = catnameptr;
tabledata[1] = schemnameptr;
tabledata[2] = tablenameptr;

tablelist = m_tablelist;
m_tablelist = new SQLWCHAR **[tablecount+1];
if (tablecount)
memcpy(m_tablelist, tablelist, sizeof(SQLWCHAR**)*tablecount);
m_tablelist[tablecount] = tabledata;
if (tablelist)
delete[] tablelist;

tablecount++;
}

tablelist = m_tablelist;
m_tablelist = new SQLWCHAR **[tablecount+1];
if (tablecount)
memcpy(m_tablelist, tablelist, sizeof(SQLWCHAR**)*tablecount);
m_tablelist[tablecount] = NULL;
if (tablelist)
delete[] tablelist;
(m_tablelist is defined in header file: SQLWCHAR ***m_tablelist)
Cleared by:
SQLWCHAR ***tablelist;
for (tablelist=m_tablelist; *tablelist; tablelist++)
{
if ((*tablelist)[0])
delete[] (*tablelist)[0];
if ((*tablelist)[1])
delete[] (*tablelist)[1];
delete[] (*tablelist)[2];

delete[] (*tablelist);
}

delete[] m_tablelist;

When second lood try to delete pointer,
system said that memory seems has been deleted.

My pgsql test db has 21 tables,
when connect to it with ODBC I always get this error.
But a excel doc has 3 sheets(will be considered as 3 tables in ODBC driver)
no error occur.

-----------------------------------------------
Quan Zongliang
quanzongliang(at)gmail(dot)com

In response to

Browse pgadmin-support by date

  From Date Subject
Next Message Angus Carr 2009-07-16 20:08:44 Roundtrip SQL bug/ unanticipated behaviour
Previous Message Quan Zongliang 2009-07-15 22:37:55 Re: I need help, about c++ pointer