Skip to content

Reset capacity_ in ShareData and ShareDiff#7115

Open
Chessing234 wants to merge 1 commit into
BVLC:masterfrom
Chessing234:fix/sharedata-reset-capacity
Open

Reset capacity_ in ShareData and ShareDiff#7115
Chessing234 wants to merge 1 commit into
BVLC:masterfrom
Chessing234:fix/sharedata-reset-capacity

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

After Blob::ShareData() or ShareDiff(), a blob can retain a stale capacity_ value even though its memory is now shared with another blob. A later Reshape() may skip reallocation when count_ <= capacity_, leaving the blob in an inconsistent state (#5439).

Root cause

ShareData/ShareDiff reassign the SyncedMemory pointer but never invalidate capacity_, so Reshape() treats the blob as still owning its previous allocation size.

Why this fix is correct

Resetting capacity_ to 0 marks the allocation as invalid after sharing, forcing Reshape() to allocate fresh memory when the blob's shape changes. This matches the behavior described in #5439 and confirmed by a maintainer.

Fixes #5439

Made with Cursor

After ShareData/ShareDiff, stale capacity_ can cause Reshape to skip
reallocation while pointing at shared memory incorrectly.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

ShareData() should reset capacity_

1 participant