Skip to content

Handle JSON memory pool allocation failures - #3663

Open
wasphin wants to merge 1 commit into
apache:masterfrom
wasphin:fix-json-pool-allocation-failure
Open

wasphin wants to merge 1 commit into
apache:masterfrom
wasphin:fix-json-pool-allocation-failure

Conversation

@wasphin

@wasphin wasphin commented Oct 25, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Problem Summary:

The JSON memory pool dereferences a failed chunk allocation and assumes a successful allocation when growing a buffer.

What is changed and the side effects?

Changed:

  • Return nullptr from pool allocation and reallocation when the backing allocator fails.
  • Preserve existing chunks and contents after a failed allocation.
  • Add a failing backing-allocator regression to CMake and Bazel.

Side effects:

  • Performance effects: Negligible checks after allocating a chunk.
  • Breaking backward compatibility: No public signature changes. This fixes the allocator contract; DOM consumers still need their own allocation-failure handling.

Check List:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized checks preserve pool state on failure, and the regression covers failure and recovery paths; tests were not executed during this review.

No open issues 🎉

What changed in this PR

This PR makes bRPC’s bundled RapidJSON memory pool handle backing-allocation failures without dereferencing null pointers or altering existing pool contents.

Changes:

  • Return null when chunk allocation or buffer growth fails.
  • Add regression coverage for allocation failures, state preservation, and successful recovery.
  • Register the regression test in CMake and Bazel.
File Description
test/​rapidjson_allocator_unittest.cc Tests failure handling, preserved contents, and recovery.
test/​CMakeLists.txt Adds the regression to the CMake test sources.
test/​BUILD.bazel Adds the regression to the Bazel test sources.
src/​butil/​third_party/​rapidjson/​allocators.h Checks allocation results before modifying chunks or copying data.

Review effort: Balanced

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.

2 participants