diff -uprN unixODBC-2.3.7/cur/SQLAllocStmt.c unixODBC-2.3.7-revised/cur/SQLAllocStmt.c
--- unixODBC-2.3.7/cur/SQLAllocStmt.c	2018-02-26 22:50:10.000000000 +0800
+++ unixODBC-2.3.7-revised/cur/SQLAllocStmt.c	2021-11-05 16:23:24.000000000 +0800
@@ -83,7 +83,7 @@ SQLRETURN CLAllocStmt( SQLHDBC connectio
                 LOG_INFO,
                 "Error: IM001" );
 
-        cl_statement -> cl_connection -> dh.__post_internal_error( &connection -> error,
+        cl_connection -> dh.__post_internal_error( &connection -> error,
                 ERROR_HY001, NULL,
                 connection -> environment -> requested_version );
 
diff -uprN unixODBC-2.3.7/cur/SQLConnect.c unixODBC-2.3.7-revised/cur/SQLConnect.c
--- unixODBC-2.3.7/cur/SQLConnect.c	2018-02-26 22:50:10.000000000 +0800
+++ unixODBC-2.3.7-revised/cur/SQLConnect.c	2021-11-05 16:23:59.000000000 +0800
@@ -299,6 +299,8 @@ SQLRETURN CLConnect( DMHDBC connection,
         cl_connection -> dh.__post_internal_error( &connection -> error,
                 ERROR_HY001, NULL,
                 connection -> environment -> requested_version );
+        
+        free( cl_connection );
         return SQL_ERROR;
     }
 
diff -uprN unixODBC-2.3.7/DriverManager/SQLCancel.c unixODBC-2.3.7-revised/DriverManager/SQLCancel.c
--- unixODBC-2.3.7/DriverManager/SQLCancel.c	2018-05-30 17:24:07.000000000 +0800
+++ unixODBC-2.3.7-revised/DriverManager/SQLCancel.c	2021-11-05 16:21:33.000000000 +0800
@@ -236,18 +236,8 @@ SQLRETURN SQLCancel( SQLHSTMT statement_
             else if ( statement -> interupted_func ==
                     SQL_API_SQLBULKOPERATIONS )
             {
-                if ( statement -> interupted_state == STATE_S5 ||
-                        statement -> interupted_state == STATE_S6 ||
-                        statement -> interupted_state == STATE_S7 )
-                {
-                    statement -> state = STATE_S6;
-                    statement -> eod = 0;
-                }
-                else
-                {
-                    statement -> state = STATE_S6;
-                    statement -> eod = 0;
-                }
+                statement -> state = STATE_S6;
+                statement -> eod = 0;
             }
             else if ( statement -> interupted_func ==
                     SQL_API_SQLSETPOS )
diff -uprN unixODBC-2.3.7/DriverManager/SQLCancelHandle.c unixODBC-2.3.7-revised/DriverManager/SQLCancelHandle.c
--- unixODBC-2.3.7/DriverManager/SQLCancelHandle.c	2018-05-30 17:24:07.000000000 +0800
+++ unixODBC-2.3.7-revised/DriverManager/SQLCancelHandle.c	2021-11-05 16:22:12.000000000 +0800
@@ -140,18 +140,8 @@ SQLRETURN SQLCancelHandle( SQLSMALLINT H
                         else if ( statement -> interupted_func ==
                                 SQL_API_SQLBULKOPERATIONS )
                         {
-                            if ( statement -> interupted_state == STATE_S5 ||
-                                    statement -> interupted_state == STATE_S6 ||
-                                    statement -> interupted_state == STATE_S7 )
-                            {
-                                statement -> state = STATE_S6;
-                                statement -> eod = 0;
-                            }
-                            else
-                            {
-                                statement -> state = STATE_S6;
-                                statement -> eod = 0;
-                            }
+                            statement -> state = STATE_S6;
+                            statement -> eod = 0;
                         }
                         else if ( statement -> interupted_func ==
                                 SQL_API_SQLSETPOS )
diff -uprN unixODBC-2.3.7/DriverManager/SQLGetConnectOption.c unixODBC-2.3.7-revised/DriverManager/SQLGetConnectOption.c
--- unixODBC-2.3.7/DriverManager/SQLGetConnectOption.c	2018-05-30 17:24:07.000000000 +0800
+++ unixODBC-2.3.7-revised/DriverManager/SQLGetConnectOption.c	2021-11-05 16:22:40.000000000 +0800
@@ -171,14 +171,7 @@ SQLRETURN SQLGetConnectOption( SQLHDBC c
     {
         if ( value )
         {
-            if ( log_info.log_flag )
-            {
-                *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
-            }
-            else
-            {
-                *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
-            }
+            *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
         }
 
         return SQL_SUCCESS;
diff -uprN unixODBC-2.3.7/DriverManager/SQLGetConnectOptionW.c unixODBC-2.3.7-revised/DriverManager/SQLGetConnectOptionW.c
--- unixODBC-2.3.7/DriverManager/SQLGetConnectOptionW.c	2018-05-30 17:24:07.000000000 +0800
+++ unixODBC-2.3.7-revised/DriverManager/SQLGetConnectOptionW.c	2021-11-05 16:23:01.000000000 +0800
@@ -110,14 +110,7 @@ SQLRETURN SQLGetConnectOptionW( SQLHDBC
     {
         if ( value )
         {
-            if ( log_info.log_flag )
-            {
-                *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
-            }
-            else
-            {
-                *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
-            }
+            *((SQLINTEGER*)value) = SQL_OPT_TRACE_ON;
         }
 
         return SQL_SUCCESS;
diff -uprN unixODBC-2.3.7/odbcinst/ODBCINSTConstructProperties.c unixODBC-2.3.7-revised/odbcinst/ODBCINSTConstructProperties.c
--- unixODBC-2.3.7/odbcinst/ODBCINSTConstructProperties.c	2015-01-23 18:32:51.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/ODBCINSTConstructProperties.c	2021-11-05 16:25:19.000000000 +0800
@@ -244,6 +244,8 @@ int ODBCINSTConstructProperties( char *p
 	/* APPEND OTHERS */
 	pODBCINSTGetProperties( hLastProperty );
 
+	lt_dlclose( hDLL );
+
 	return ODBCINST_SUCCESS;
 }
 
diff -uprN unixODBC-2.3.7/odbcinst/SQLConfigDriver.c unixODBC-2.3.7-revised/odbcinst/SQLConfigDriver.c
--- unixODBC-2.3.7/odbcinst/SQLConfigDriver.c	2015-01-23 18:31:25.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/SQLConfigDriver.c	2021-11-05 16:26:47.000000000 +0800
@@ -24,7 +24,6 @@ static BOOL SQLConfigDriverWide( HWND	hW
 								LPWSTR	pszMsgW,
 								int 	*iswide )
 {
-	BOOL	nReturn;
 	void 	*hDLL;
 	BOOL	(*pConfigDriver)( HWND, WORD, LPCSTR, LPCSTR, LPCSTR, WORD, WORD *	);
 	BOOL	(*pConfigDriverW)( HWND, WORD, LPCWSTR, LPCWSTR, LPCWSTR, WORD, WORD *	);
@@ -36,7 +35,6 @@ static BOOL SQLConfigDriverWide( HWND	hW
 	*iswide = 0;
 
 	/* SANITY CHECKS */
-    nReturn = FALSE;
 	if ( pszDriver == NULL )
 	{
 		inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_NAME, "" );
@@ -109,14 +107,17 @@ static BOOL SQLConfigDriverWide( HWND	hW
 			pConfigDriverW = (BOOL (*)(HWND, WORD, LPCWSTR, LPCWSTR, LPCWSTR, WORD, WORD * )) lt_dlsym( hDLL, "ConfigDriverW" );
 /*			if ( lt_dlerror() == NULL ) */
             if ( pConfigDriver )
-				nReturn = pConfigDriver( hWnd, nRequest, pszDriver, pszArgs, pszMsg, nMsgMax, pnMsgOut);
+				(void) pConfigDriver( hWnd, nRequest, pszDriver, pszArgs, pszMsg, nMsgMax, pnMsgOut);
 			else if ( pConfigDriverW )
 			{
-				nReturn = pConfigDriverW( hWnd, nRequest, pszDriverW, pszArgsW, pszMsgW, nMsgMax, pnMsgOut);
+				(void) pConfigDriverW( hWnd, nRequest, pszDriverW, pszArgsW, pszMsgW, nMsgMax, pnMsgOut);
 				*iswide = 1;
 			}
 			else
+			{
 				inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
+			}
+			lt_dlclose( hDLL );
 		}
 		else
 			inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
diff -uprN unixODBC-2.3.7/odbcinst/SQLCreateDataSource.c unixODBC-2.3.7-revised/odbcinst/SQLCreateDataSource.c
--- unixODBC-2.3.7/odbcinst/SQLCreateDataSource.c	2018-06-28 19:13:00.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/SQLCreateDataSource.c	2021-11-05 16:31:48.000000000 +0800
@@ -242,10 +242,18 @@ BOOL SQLCreateDataSource( HWND hWnd, LPC
     {
         /* change the name, as it avoids it finding it in the calling lib */
         pSQLCreateDataSource = (BOOL (*)(HWND, LPCSTR))lt_dlsym( hDLL, "ODBCCreateDataSource" );
-        if ( pSQLCreateDataSource )
-            return pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), pszDS );
+
+        if ( pSQLCreateDataSource ) {
+            BOOL ret;
+
+            ret = pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), pszDS );
+
+            lt_dlclose( hDLL );
+            return ret;
+        }
         else
             inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+        lt_dlclose( hDLL );
     }
     else
     {
@@ -256,10 +264,18 @@ BOOL SQLCreateDataSource( HWND hWnd, LPC
         {
             /* change the name, as it avoids linker finding it in the calling lib */
             pSQLCreateDataSource = (BOOL (*)(HWND,LPCSTR))lt_dlsym( hDLL, "ODBCCreateDataSource" );
-            if ( pSQLCreateDataSource )
-                return pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), pszDS );
+
+            if ( pSQLCreateDataSource ) {
+                BOOL ret;
+
+                ret = pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), pszDS );
+
+                lt_dlclose( hDLL );
+                return ret;
+            }
             else
                 inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+            lt_dlclose( hDLL );
         }
     }
 
@@ -308,10 +324,17 @@ BOOL INSTAPI SQLCreateDataSourceW( HWND
     {
         /* change the name, as it avoids it finding it in the calling lib */
         pSQLCreateDataSource = (BOOL (*)(HWND, LPCWSTR))lt_dlsym( hDLL, "ODBCCreateDataSourceW" );
-        if ( pSQLCreateDataSource )
-            return pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), lpszDSN );
+        if ( pSQLCreateDataSource ) {
+            BOOL ret;
+
+            ret = pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), lpszDSN );
+
+            lt_dlclose( hDLL );
+            return ret;
+        }
         else
             inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+        lt_dlclose( hDLL );
     }
     else
     {
@@ -322,10 +345,17 @@ BOOL INSTAPI SQLCreateDataSourceW( HWND
         {
             /* change the name, as it avoids linker finding it in the calling lib */
             pSQLCreateDataSource = (BOOL (*)(HWND,LPCWSTR))lt_dlsym( hDLL, "ODBCCreateDataSourceW" );
-            if ( pSQLCreateDataSource )
-                return pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), lpszDSN );
+            if ( pSQLCreateDataSource ) {
+                BOOL ret;
+
+                ret = pSQLCreateDataSource( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), lpszDSN );
+
+                lt_dlclose( hDLL );
+                return ret;
+            }
             else
                 inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+            lt_dlclose( hDLL );
         }
     }
 
diff -uprN unixODBC-2.3.7/odbcinst/_SQLDriverConnectPrompt.c unixODBC-2.3.7-revised/odbcinst/_SQLDriverConnectPrompt.c
--- unixODBC-2.3.7/odbcinst/_SQLDriverConnectPrompt.c	2018-04-03 18:34:02.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/_SQLDriverConnectPrompt.c	2021-11-05 16:40:43.000000000 +0800
@@ -12,6 +12,7 @@ BOOL _SQLDriverConnectPrompt(
     char          szPathAndName[FILENAME_MAX];
     void *        hDLL;
     BOOL          (*pODBCDriverConnectPrompt)(HWND, SQLCHAR *, SQLSMALLINT );
+	BOOL          ret;
 
     /* initialize libtool */
     if ( lt_dlinit() )
@@ -40,17 +41,21 @@ BOOL _SQLDriverConnectPrompt(
 		{
 			if ( hODBCInstWnd ) 
 			{
-            	return pODBCDriverConnectPrompt(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
+            	ret = pODBCDriverConnectPrompt(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
 			}
 			else 
 			{
-            	return pODBCDriverConnectPrompt( NULL, dsn, len_dsn );
+            	ret = pODBCDriverConnectPrompt( NULL, dsn, len_dsn );
 			}
 		}
 		else 
 		{
-			return FALSE;
+			ret = FALSE;
 		}
+
+		lt_dlclose( hDLL );
+
+		return ret;
     }
     else
     {
@@ -65,17 +70,20 @@ BOOL _SQLDriverConnectPrompt(
 			{
 				if ( hODBCInstWnd ) 
 				{
-            		return pODBCDriverConnectPrompt(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
+            		ret = pODBCDriverConnectPrompt(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
 				}
 				else 
 				{
-            		return pODBCDriverConnectPrompt( NULL, dsn, len_dsn );
+            		ret = pODBCDriverConnectPrompt( NULL, dsn, len_dsn );
 				}
 			}
 			else 
 			{
-				return FALSE;
+				ret = FALSE;
 			}
+
+			lt_dlclose( hDLL );
+			return ret;
         }
     }
 
@@ -93,6 +101,7 @@ BOOL _SQLDriverConnectPromptW(
     char          szPathAndName[FILENAME_MAX];
     void *        hDLL;
     BOOL          (*pODBCDriverConnectPromptW)(HWND, SQLWCHAR *, SQLSMALLINT );
+	BOOL          ret;
 
     /* initialize libtool */
     if ( lt_dlinit() )
@@ -121,17 +130,20 @@ BOOL _SQLDriverConnectPromptW(
 		{
 			if ( hODBCInstWnd ) 
 			{
-            	return pODBCDriverConnectPromptW(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
+            	ret = pODBCDriverConnectPromptW(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
 			}
 			else 
 			{
-            	return pODBCDriverConnectPromptW( NULL, dsn, len_dsn );
+            	ret = pODBCDriverConnectPromptW( NULL, dsn, len_dsn );
 			}
 		}
 		else 
 		{
-			return FALSE;
+			ret = FALSE;
 		}
+
+		lt_dlclose( hDLL );
+		return ret;
     }
     else
     {
@@ -146,17 +158,20 @@ BOOL _SQLDriverConnectPromptW(
 			{
 				if ( hODBCInstWnd ) 
 				{
-            		return pODBCDriverConnectPromptW(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
+            		ret = pODBCDriverConnectPromptW(( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ), dsn, len_dsn );
 				}
 				else 
 				{
-            		return pODBCDriverConnectPromptW( NULL, dsn, len_dsn );
+            		ret = pODBCDriverConnectPromptW( NULL, dsn, len_dsn );
 				}
 			}
 			else 
 			{
-				return FALSE;
+				ret = FALSE;
 			}
+
+			lt_dlclose( hDLL );
+			return ret;
         }
     }
 
diff -uprN unixODBC-2.3.7/odbcinst/SQLManageDataSources.c unixODBC-2.3.7-revised/odbcinst/SQLManageDataSources.c
--- unixODBC-2.3.7/odbcinst/SQLManageDataSources.c	2018-03-28 17:04:04.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/SQLManageDataSources.c	2021-11-05 16:36:24.000000000 +0800
@@ -153,10 +153,16 @@ BOOL SQLManageDataSources( HWND hWnd )
     {
         /* change the name (SQLManageDataSources to ODBCManageDataSources) to prevent us from calling ourself */
         pSQLManageDataSources = (BOOL (*)(HWND))lt_dlsym( hDLL, "ODBCManageDataSources" );
-        if ( pSQLManageDataSources )
-            return pSQLManageDataSources( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ) );
+        if ( pSQLManageDataSources ) {
+            BOOL ret;
+            ret = pSQLManageDataSources( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ) );
+
+            lt_dlclose( hDLL );
+            return ret;
+        }
         else
             inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+        lt_dlclose( hDLL );
     }
     else
     {
@@ -169,10 +175,17 @@ BOOL SQLManageDataSources( HWND hWnd )
             /* change the name (SQLManageDataSources to ODBCManageDataSources) to prevent us from calling ourself   */
             /* its only safe to use hWnd if szUI was specified by the caller                                        */
             pSQLManageDataSources = (BOOL (*)(HWND))lt_dlsym( hDLL, "ODBCManageDataSources" );
-            if ( pSQLManageDataSources )
-                return pSQLManageDataSources( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ) );
+            if ( pSQLManageDataSources ) {
+                BOOL ret;
+
+                ret = pSQLManageDataSources( ( *(hODBCInstWnd->szUI) ? hODBCInstWnd->hWnd : NULL ) );
+
+                lt_dlclose( hDLL );
+                return ret;
+            }
             else
                 inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
+            lt_dlclose( hDLL );
         }
         else
             inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
diff -uprN unixODBC-2.3.7/odbcinst/SQLReadFileDSN.c unixODBC-2.3.7-revised/odbcinst/SQLReadFileDSN.c
--- unixODBC-2.3.7/odbcinst/SQLReadFileDSN.c	2014-01-06 17:37:02.000000000 +0800
+++ unixODBC-2.3.7-revised/odbcinst/SQLReadFileDSN.c	2021-11-05 16:37:43.000000000 +0800
@@ -87,7 +87,6 @@ BOOL SQLReadFileDSN(            LPCSTR
                                 WORD    *pnString )
 {
     HINI    hIni;
-    int     nBufPos         = 0;
     char    szValue[INI_MAX_PROPERTY_VALUE+1];
     char    szFileName[ODBC_FILENAME_MAX+1];
 
@@ -186,6 +185,10 @@ BOOL SQLReadFileDSN(            LPCSTR
             inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL,
                              ODBC_ERROR_REQUEST_FAILED, "" );
 
+            if ( pszFileName )
+            {
+                iniClose( hIni );
+            }
             return FALSE;
         }
         else
@@ -193,7 +196,6 @@ BOOL SQLReadFileDSN(            LPCSTR
             iniValue( hIni, szValue );
             strncpy( pszString, szValue, nString );
             pszString[ nString - 1 ] = '\0';
-            nBufPos = strlen( szValue );
         }
     }
 
diff -uprN unixODBC-2.3.7/.vscode/settings.json unixODBC-2.3.7-revised/.vscode/settings.json
--- unixODBC-2.3.7/.vscode/settings.json	1970-01-01 08:00:00.000000000 +0800
+++ unixODBC-2.3.7-revised/.vscode/settings.json	2021-11-05 16:20:50.000000000 +0800
@@ -0,0 +1,4 @@
+{
+    "C_Cpp.autocomplete": "Disabled",
+    "C_Cpp.intelliSenseEngine": "Disabled"
+}
\ No newline at end of file
