Skip to content

Commit

Permalink
Plug leak of "match_args" in StructMeta.
Browse files Browse the repository at this point in the history
"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
```
  • Loading branch information
peadar authored and jcrist committed May 10, 2024
1 parent 13a06dd commit 5e4068c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6810,6 +6810,7 @@ StructMeta_clear(StructMetaObject *self)
Py_CLEAR(self->rename);
Py_CLEAR(self->post_init);
Py_CLEAR(self->struct_info);
Py_CLEAR(self->match_args);
if (self->struct_offsets != NULL) {
PyMem_Free(self->struct_offsets);
self->struct_offsets = NULL;
Expand Down

0 comments on commit 5e4068c

Please sign in to comment.