Skip to content

Plug leak of "match_args" in StructMeta.#684

Merged
jcrist merged 1 commit intojcrist:mainfrom
peadar:leak-match-args
May 10, 2024
Merged

Plug leak of "match_args" in StructMeta.#684
jcrist merged 1 commit intojcrist:mainfrom
peadar:leak-match-args

Conversation

@peadar
Copy link
Copy Markdown
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
Copy Markdown
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
@peadar
Copy link
Copy Markdown
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.

2 participants