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

Plug leak of "match_args" in StructMeta. #684

Merged
merged 1 commit into from
May 10, 2024
Merged

Conversation

peadar
Copy link
Contributor

@peadar peadar commented May 10, 2024

"match_args" is set in StructMetaInfo and eventually StructMeta via -

 info->match_args = PyTuple_GetSlice(info->fields, 0, nfields - nkwonly);

This is incref'd before copying to StructMeta, and decref'd when cleaning up StructMetaInfo. There's no corresponding decref for StructMeta itself. This causes a leak that valgrind readily detects:

env PYTHONMALLOC=malloc valgrind python3 -c 'import msgspec'
...
==576283== LEAK SUMMARY:
==576283==    definitely lost: 1,608 bytes in 26 blocks

With the fix in place, we get:

==576086== LEAK SUMMARY:
==576086==    definitely lost: 0 bytes in 0 blocks

"match_args" is set in StructMetaInfo and eventually StructMeta via -

```
 info->match_args = PyTuple_GetSlice(info->fields, 0, nfields - nkwonly);
```

This is incref'd before copying to StructMeta, and decref'd when
cleaning up StructMetaInfo. There's no corresponding decref for
StructMeta itself. This causes a leak that valgrind readily detects:

```
env PYTHONMALLOC=malloc valgrind python3 -c 'import msgspec'
...
==576283== LEAK SUMMARY:
==576283==    definitely lost: 1,608 bytes in 26 blocks
```

With the fix in place, we get:

```
==576086== LEAK SUMMARY:
==576086==    definitely lost: 0 bytes in 0 blocks
```
Copy link
Owner

@jcrist jcrist left a comment

Choose a reason for hiding this comment

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

Thanks!

@jcrist jcrist merged commit 5e4068c into jcrist:main May 10, 2024
8 checks passed
@peadar
Copy link
Contributor Author

peadar commented May 10, 2024

Thank you for the fast response and merge!

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.

None yet

2 participants