Commit ce44d0e
Fix rmem page released while a later chunk still points into it
_msgpack_buffer_chunk_malloc hands the current rmem page over to the
chunk that carves the reclaimed space out of it, but b->rmem_owner was
always an alias of &b->tail.mem: _msgpack_buffer_add_new_chunk copies
b->tail into a new chunk without repointing the owner, so the transfer
degenerated into a self-assignment that immediately nulled the pointer.
The page stayed owned by the older chunk instead, and because chunks are
destroyed head first, it was returned to the process global pool while
the rebuilt tail was still reading from it. Another buffer allocating a
page then received the very same memory: reads returned that buffer's
bytes and further writes corrupted it.
Let the owner follow the page when the tail is copied, so the newest
chunk carved out of a page is the one that releases it.
Also drop the carve window in _msgpack_buffer_shift_chunk when the
chunk owning the current page is destroyed. rmem_last / rmem_end kept
pointing into that page, so a later small write could carve a new chunk
out of a page that was already back in the pool.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 8ab8a5a commit ce44d0e
2 files changed
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
130 | 139 | | |
131 | 140 | | |
132 | 141 | | |
| |||
264 | 273 | | |
265 | 274 | | |
266 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
267 | 288 | | |
268 | 289 | | |
269 | 290 | | |
| |||
275 | 296 | | |
276 | 297 | | |
277 | 298 | | |
| 299 | + | |
278 | 300 | | |
279 | 301 | | |
280 | 302 | | |
| |||
295 | 317 | | |
296 | 318 | | |
297 | 319 | | |
| 320 | + | |
298 | 321 | | |
299 | 322 | | |
300 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
623 | 668 | | |
0 commit comments