Bug #3743 Access Violation while SQLConnect
Submitted: 13 May 2004 12:49 Modified: 3 Jun 2005 19:59
Reporter: Sören Rose Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.06 OS:Windows (Win2000)
Assigned to: Timothy Smith CPU Architecture:Any

[13 May 2004 12:49] Sören Rose
Description:

In the Function my_SQLAllocConnect, called in SQLConnect, Global Mem is allocated.
>>
    HGLOBAL hdbc = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (DBC));
    if (!hdbc || (*phdbc = (SQLHDBC)GlobalLock (hdbc)) == SQL_NULL_HDBC)
    {
      GlobalFree (hdbc);
      *phdbc = SQL_NULL_HENV;
      return (set_env_error(henv,MYERR_S1001,NULL,0));
    }
<<
What if GlobalAlloc return NULL ? GlobalFree would get NULL to free and an access violation occurs (MSDN).
I have an Access Violation while makíng a connect.

How to repeat:

Difficult, because depends on result of GlobalAlloc.

Suggested fix:

Do not free, if hdbc==0.
[17 May 2004 12:24] Sören Rose
Message fom Driver:

"Memory allocation error. Fehler beim SQLAllocHandle-Aufruf für Treiber auf  SQL_HANDLE_DBC."

"State:S1001,Native:517,Origin:[MySQL][ODBC 3.51 Driver]
State:IM005,Native:0,Origin:[Microsoft][ODBC Driver Manager]"
[18 May 2004 8:40] Sören Rose
If GlobalAlloc fails, why there is no GetLastError, to get extended error information? Would be nice to find out, why it fails.
[25 Jul 2004 6:19] Peter Harvey
Fix in bk - will be in this weeks release of MyODBC 3.51.9.