buffer bound handling in jemalloc stats callback to avoid unintended growth#19334
Open
jmestwa-coder wants to merge 1 commit into
Open
buffer bound handling in jemalloc stats callback to avoid unintended growth#19334jmestwa-coder wants to merge 1 commit into
jmestwa-coder wants to merge 1 commit into
Conversation
577930e to
2afb2d9
Compare
2afb2d9 to
0f22457
Compare
Contributor
Author
|
kindly review this PR. Thank you! |
e23b1fe to
2804036
Compare
2804036 to
f28eb96
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes incorrect bound handling in the jemalloc stats callback (
write_cb).The callback previously used the buffer’s total capacity instead of the remaining space (
capacity - len). This allowed the buffer to grow across multiple invocations, exceeding the intended limit and potentially triggering reallocation inside the callback, which is explicitly undesirable in this context.This change ensures that each write is bounded by the remaining capacity. Once the buffer is full, the callback returns early and performs no further writes.
How Has This Been Tested?
Key Areas to Review
write_cblogic:capacity - len(viasaturating_sub) to compute remaining spaceType of Change
Which Components or Systems Does This Change Impact?
Checklist
Note
Low Risk
Low risk bug fix limited to the jemalloc stats output callback; it only changes how bytes are appended to a preallocated buffer to avoid exceeding the intended max length or reallocating in the callback.
Overview
Fixes the jemalloc
malloc_stats_printwrite callback to respect remaining buffer capacity (capacity - len) instead of total capacity.When the stats buffer is full, the callback now returns early and truncates each write to the remaining space, preventing unintended growth/reallocation during stats collection.
Reviewed by Cursor Bugbot for commit f28eb96. Bugbot is set up for automated code reviews on this repo. Configure here.