Skip to content
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

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

miscco
Copy link
Contributor

@miscco miscco commented Nov 27, 2021

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 works

Also add tests for the error cases

@brevzin

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
@miscco miscco requested a review from a team as a code owner November 27, 2021 09:54
_State |= _From_rvalue;
if ((_State & _Noread) && (_State & _Constant)) { // Cannot read / write buffer, do nothing
_Seekhigh = nullptr;
_Mystate = _State | _From_rvalue;
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to keep.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Nov 30, 2021
@@ -189,6 +189,7 @@ public:
_Mystate &= ~_Allocated;
}
}

Copy link
Member

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

Copy link
Member

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.

@barcharcraz barcharcraz removed their assignment Dec 11, 2021
@StephanTLavavej StephanTLavavej self-assigned this Dec 16, 2021
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 7c78a42 into microsoft:main Dec 17, 2021
@StephanTLavavej
Copy link
Member

Thanks for finding and fixing this memory leak! 🔍 🛠️ 😸

@miscco miscco deleted the fix_streambuf branch December 17, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants