FIX: Segmentation Fault in libmsodbcsql-18.5 during SQLFreeHandle() by subrata-ms ยท Pull Request #415 ยท microsoft/mssql-python
๐ Code Coverage Report
๐ฅ Diff Coverage78% |
๐ฏ Overall Coverage76% |
๐ Total Lines Covered: |
Diff Coverage
Diff: main...HEAD, staged and unstaged changes
- mssql_python/pybind/connection/connection.cpp (90.7%): Missing lines 127-130
- mssql_python/pybind/ddbc_bindings.cpp (38.5%): Missing lines 1154-1158,1193-1195
Summary
- Total: 56 lines
- Missing: 12 lines
- Coverage: 78%
mssql_python/pybind/connection/connection.cpp
Lines 123-134
123 // SAFETY ASSERTION: Only STMT handles should be in this vector 124 // This is guaranteed by allocStatementHandle() which only creates STMT handles 125 // If this assertion fails, it indicates a serious bug in handle tracking 126 if (handle->type() != SQL_HANDLE_STMT) { ! 127 LOG_ERROR("CRITICAL: Non-STMT handle (type=%d) found in _childStatementHandles. " ! 128 "This will cause a handle leak!", handle->type()); ! 129 continue; // Skip marking to prevent leak ! 130 } 131 handle->markImplicitlyFreed(); 132 } 133 } 134 _childStatementHandles.clear();
mssql_python/pybind/ddbc_bindings.cpp
Lines 1150-1162
1150 // Other handle types (ENV, DBC, DESC) are NOT automatically freed by parents. 1151 // Calling this on wrong handle types will cause silent handle leaks. 1152 if (_type != SQL_HANDLE_STMT) { 1153 // Log error but don't throw - we're likely in cleanup/destructor path ! 1154 LOG_ERROR("SAFETY VIOLATION: Attempted to mark non-STMT handle as implicitly freed. " ! 1155 "Handle type=%d. This will cause handle leak. Only STMT handles are " ! 1156 "automatically freed by parent DBC handles.", _type); ! 1157 return; // Refuse to mark - let normal free() handle it ! 1158 } 1159 _implicitly_freed = true; 1160 } 1161 1162 /*
Lines 1189-1199
1189 // frees all child STMT handles. We track this state to avoid double-free attempts. 1190 // This approach avoids calling ODBC functions on potentially-freed handles, which 1191 // would cause use-after-free errors. 1192 if (_implicitly_freed) { ! 1193 _handle = nullptr; // Just clear the pointer, don't call ODBC functions ! 1194 return; ! 1195 } 1196 1197 // Handle is valid and not implicitly freed, proceed with normal freeing 1198 SQLFreeHandle_ptr(_type, _handle); 1199 _handle = nullptr;
๐ Files Needing Attention
๐ Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.hpp: 58.8% mssql_python.pybind.logger_bridge.cpp: 59.2% mssql_python.row.py: 66.2% mssql_python.pybind.ddbc_bindings.cpp: 69.3% mssql_python.pybind.ddbc_bindings.h: 69.7% mssql_python.pybind.connection.connection.cpp: 75.3% mssql_python.ddbc_bindings.py: 79.6% mssql_python.pybind.connection.connection_pool.cpp: 79.6% mssql_python.connection.py: 84.1% mssql_python.cursor.py: 84.7%