--- libiodbc2-3.52.6.orig/iodbc/herr.c  2007-10-07 16:09:10.000000000 +0200
+++ libiodbc2-3.52.6/iodbc/herr.c       2009-10-19 11:30:54.000000000 +0200
@@ -363,10 +363,10 @@

   if (herr == SQL_NULL_HERR)   /* no err on drv mng */
     {
-      if (((DBC_t *)hdbc)->genv)
+      if (hdbc && ((DBC_t *)hdbc)->genv)
         odbc_ver = ((GENV_t *) ((DBC_t *)hdbc)->genv)->odbc_ver;

-      if (((DBC_t *)hdbc)->henv)
+      if (hdbc && ((DBC_t *)hdbc)->henv)
         {
           unicode_driver = ((ENV_t *) ((DBC_t *)hdbc)->henv)->unicode_driver;
           dodbc_ver = ((ENV_t *) ((DBC_t *)hdbc)->henv)->dodbc_ver;
@@ -939,13 +939,13 @@
        }
       RecNumber -= nRecs;

-      if (((DBC_t *)hdbc)->henv)
+      if (hdbc && ((DBC_t *)hdbc)->henv)
         {
           unicode_driver = ((ENV_t *) ((DBC_t *)hdbc)->henv)->unicode_driver;
           dodbc_ver = ((ENV_t *) ((DBC_t *)hdbc)->henv)->dodbc_ver;
         }

-      if (((DBC_t *)hdbc)->genv)
+      if (hdbc && ((DBC_t *)hdbc)->genv)
         odbc_ver = ((GENV_t *) ((DBC_t *)hdbc)->genv)->odbc_ver;

       if ((unicode_driver && waMode != 'W')
