-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix Efficient access to streambuf buffer #2361
Conversation
Currently we were always taking the buffer from the moved in string, but would only take it when the buffer could be read or written to. Consequently if that was not the case we would leak the allocated memory. Also simplify the code a bit, we know that the capacity `_Res` will always be nonzero due to the was `_Release_to_buffer` works Also add tests for the error cases
_State |= _From_rvalue; | ||
if ((_State & _Noread) && (_State & _Constant)) { // Cannot read / write buffer, do nothing | ||
_Seekhigh = nullptr; | ||
_Mystate = _State | _From_rvalue; |
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.
I am slightly unsure whether the _From_rvalue
is really applicable here
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.
Seems reasonable to keep.
@@ -189,6 +189,7 @@ public: | |||
_Mystate &= ~_Allocated; | |||
} | |||
} | |||
|
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.
This appears to be a stray change, although we do usually seperate the statements following an else block with a single newline
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.
I'm okay with this small drive-by style improvement.
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for finding and fixing this memory leak! 🔍 🛠️ 😸 |
Currently we were always taking the buffer from the moved in string, but would only store it when the buffer could be read or written to.
Consequently if that was not the case we would leak the allocated memory.
Also simplify the code a bit, we know that the capacity
_Res
will always be nonzero due to the way_Release_to_buffer
worksAlso add tests for the error cases
@brevzin