Skip to content

fix deallocate arguments in monotonic_resource and string_impl - #1179

Open
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:deallocate-size-align
Open

fix deallocate arguments in monotonic_resource and string_impl#1179
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:deallocate-size-align

Conversation

@Ramya-9353

@Ramya-9353 Ramya-9353 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Repro: parse anything through a monotonic_resource whose upstream is test/checking_resource.hpp. Every block fails size == it->second.first.

Cause: do_allocate asks the upstream for sizeof(block) + next_size_ but records only next_size_ in block::size, so release() returns each block 32 bytes short on LP64. The default resource ignores the size argument, so this only bites upstreams that bucket by size.

Fix: add the header size back before deallocating. The key-string alignment fix that was originally part of this PR moved to #1181.

@cppalliance-bot

cppalliance-bot commented Aug 3, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1179.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-08-05 16:56:48 UTC

@cppalliance-bot

cppalliance-bot commented Aug 3, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://1179.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1179.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1179.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-08-05 17:05:59 UTC

@cppalliance-bot

Copy link
Copy Markdown

@grisumbras grisumbras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for catching these serious issues.

sp->deallocate(k_.s, k_.n + 1);
sp->deallocate(k_.s, k_.n + 1,
alignof(char));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this is a correct fix, it is unrelated to the topic of this commit. Please move to a separate PR.

Btw, you don't have to add a line here, the extra argument perfectly fits into 80 columns, which is what I use as the threshold.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, moved it to #1181 and kept the call on one line there.

Comment thread test/monotonic_resource.cpp Outdated
{
checking_resource res;
monotonic_resource mr(1024, &res);
mr.allocate(1000, alignof(core::max_align_t));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://drone.cpp.al/boostorg/json/2138/1/2

Silence these warnings with a cast to void (e.g. (void)mr.allocate...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, cast to void.

Comment thread test/monotonic_resource.cpp Outdated
mr.allocate(4000, alignof(core::max_align_t));
}

{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test does not appear to be necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped it, the direct allocate calls already cover the block bookkeeping.

Comment thread test/parse.cpp Outdated
}

void
testAllocation()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I presume, this should also be a part of a separate PR centered on requesting correct alignment in string deallocation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, moved to #1181 along with the alignment fix.

@Ramya-9353

Copy link
Copy Markdown
Contributor Author

Trimmed this down to just the monotonic_resource size fix, with the warnings silenced and the parse-through-monotonic test dropped. The key-string alignment fix and its test are now #1181.

@cppalliance-bot

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants