Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in Raw.copy(). #709

Merged
merged 2 commits into from
Oct 13, 2024
Merged

Fix memory leak in Raw.copy(). #709

merged 2 commits into from
Oct 13, 2024

Conversation

tjgq
Copy link
Contributor

@tjgq tjgq commented Jul 12, 2024

Raw_New borrows a reference to its PyBytesObject argument, so Raw_Copy must still dispose of it.

The following is a minimal repro for this issue:

import msgspec

DECODER = msgspec.msgpack.Decoder(type=msgspec.Raw)
PAYLOAD = b"\xda\xff\xff" + (65535 * b"\0") # array of 65535 zeros

for _ in range(1000000):
  raw = DECODER.decode(PAYLOAD)
  raw.copy()

@tjgq tjgq marked this pull request as ready for review July 12, 2024 19:15
@tjgq
Copy link
Contributor Author

tjgq commented Jul 15, 2024

@jcrist could you please take a look?

tjgq and others added 2 commits October 13, 2024 12:41
Raw_New borrows a reference to its PyBytesObject argument, so Raw_Copy must
still dispose of it.

The following is a minimal repro for this issue:

import msgspec

DECODER = msgspec.msgpack.Decoder(type=msgspec.Raw)
PAYLOAD = b"\xda\xff\xff" + (65535 * b"\0") # array of 65535 zeros

for _ in range(1000000):
  raw = DECODER.decode(PAYLOAD)
  raw.copy()
@jcrist jcrist merged commit 51a261c into jcrist:main Oct 13, 2024
7 checks passed
@jcrist
Copy link
Owner

jcrist commented Oct 13, 2024

Thanks!

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