jcrist / msgspec

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
https://jcristharif.com/msgspec/
BSD 3-Clause "New" or "Revised" License
2.01k stars 59 forks source link

Plug leak of "match_args" in StructMeta. #684

Closed peadar closed 1 month ago

peadar commented 1 month ago

"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
peadar commented 1 month ago

Thank you for the fast response and merge!