-
Notifications
You must be signed in to change notification settings - Fork 27
FIX: Handling Access token with class level variables and removing static defination #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a memory accumulation issue in the Connection::setAttribute method by replacing static vectors that indefinitely stored attribute values with class-level buffers. The static vectors were unnecessary since attribute values only need to persist for the duration of the ODBC API call.
Key changes:
- Removed static
std::vector<std::wstring>andstd::vector<std::string>buffers that accumulated historical attribute values - Introduced two class-level member variables (
wstrStringBufferandstrBytesBuffer) to temporarily hold attribute data - Removed buffer size management code (MAX_BUFFER_COUNT logic) that was previously needed to prevent unbounded growth
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mssql_python/pybind/connection/connection.h | Adds two class-level buffer member variables for storing string and byte attribute data |
| mssql_python/pybind/connection/connection.cpp | Replaces static vector buffers with class-level buffers and removes buffer management logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@subrata-ms please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information. @microsoft-github-policy-service agree [company="{your company}"] (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer. |
|
@microsoft-github-policy-service agree company="Microsoft" |
sumitmsft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/pybind/connection/connection.cppLines 254-265 254 } else if (py::isinstance<py::bytes>(value) ||
255 py::isinstance<py::bytearray>(value)) {
256 try {
257 std::string binary_data = value.cast<std::string>();
! 258 this->strBytesBuffer.clear();
! 259 this->strBytesBuffer = std::move(binary_data);
! 260 SQLPOINTER ptr = const_cast<char*>(this->strBytesBuffer.c_str());
! 261 SQLINTEGER length = static_cast<SQLINTEGER>(this->strBytesBuffer.size());
262
263 SQLRETURN ret = SQLSetConnectAttr_ptr(_dbcHandle->get(),
264 attribute, ptr, length);
265 if (!SQL_SUCCEEDED(ret)) {📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.helpers.py: 67.8%
mssql_python.pybind.ddbc_bindings.cpp: 70.7%
mssql_python.pybind.connection.connection.cpp: 75.9%
mssql_python.pybind.connection.connection_pool.cpp: 78.9%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.ddbc_bindings.h: 79.7%
mssql_python.auth.py: 87.1%
mssql_python.pooling.py: 87.7%
mssql_python.__init__.py: 90.9%
mssql_python.exceptions.py: 92.8%🔗 Quick Links
|
Work Item / Issue Reference
Summary
This pull request refactors the way temporary buffers are managed for setting connection attributes in the
Connectionclass, improving memory safety and simplifying buffer handling. Instead of using static vectors to store temporary string and binary data, the code now uses member variables to hold these buffers directly within eachConnectioninstance.Buffer Management Refactor:
wstr_buffers,buffers) for storing temporary wide string and binary buffers, eliminating the need for manual buffer growth management and cleanup. [1] [2] [3]wstrStringBufferandstrBytesBufferto theConnectionclass for managing temporary buffers per connection instance, improving encapsulation and memory safety.setAttributeto use these new member variables, replacing references to static buffers with instance variables. [1] [2] [3]Code Simplification: