Skip to content

Fix Meta(pattern=..) memory leak / corruption - #1256

Merged
sobolevn merged 7 commits into
mainfrom
fix-meta-leak
Oct 12, 2026
Merged

sobolevn merged 7 commits into
mainfrom
fix-meta-leak

Conversation

@sobolevn

@sobolevn sobolevn commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

MS_CONSTR_STR_REGEX slot clear was missing. It was not properly traversed and freed. Now it is.

It used to fail with memory sanitized with:

 ==2637==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x50e000e8e350 in thread T0
    #0 0x7f07a10fc4d8 in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
    #1 0x7f079c42ddf4 in TypeNode_Free src/msgspec/_core.c:3474
    #2 0x7f079c42dbdf in TypeNode_Free src/msgspec/_core.c:3468
    #3 0x7f079c55e2eb in JSONDecoder_dealloc src/msgspec/_core.c:17235
    #4 0x7f07a0999132 in _PyEval_EvalFrameDefault Python/bytecodes.c:1398
    #5 0x7f07a0a15f73 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:92
    #6 0x7f07a0a15f73 in method_vectorcall Objects/classobject.c:69
    #7 0x7f07a098d82f in _PyEval_EvalFrameDefault Python/bytecodes.c:3263
    #8 0x7f07a0a14e6c in _PyFunction_Vectorcall Objects/call.c:419
    #9 0x7f07a0a14e6c in _PyObject_FastCallDictTstate Objects/call.c:144
    #10 0x7f07a0a14e6c in _PyObject_Call_Prepend Objects/call.c:508
    #11 0x7f07a0ac3381 in slot_tp_call Objects/typeobject.c:8791
    #12 0x7f07a0a14206 in _PyObject_MakeTpCall Objects/call.c:240
    #13 0x7f07a098d20a in _PyEval_EvalFrameDefault Python/bytecodes.c:2715
    #14 0x7f07a0a14e6c in _PyFunction_Vectorcall Objects/call.c:419
    #15 0x7f07a0a14e6c in _PyObject_FastCallDictTstate Objects/call.c:144
    #16 0x7f07a0a14e6c in _PyObject_Call_Prepend Objects/call.c:508
    #17 0x7f07a0ac3381 in slot_tp_call Objects/typeobject.c:8791
    #18 0x7f07a0a1550e in PyObject_Call (/opt/hostedtoolcache/Python/3.12.15/x64/lib/libpython3.12.so.1.0+0x21550e) (BuildId: d5ce433e66c26342bfaf6b82ab1a95541a8ebade)
    #19 0x7f07a098d82f in _PyEval_EvalFrameDefault Python/bytecodes.c:3263
    #20 0x7f07a0a14e6c in _PyFunction_Vectorcall Objects/call.c:419
    #21 0x7f07a0a14e6c in _PyObject_FastCallDictTstate Objects/call.c:144
    #22 0x7f07a0a14e6c in _PyObject_Call_Prepend Objects/call.c:508
    #23 0x7f07a0ac3381 in slot_tp_call Objects/typeobject.c:8791
    #24 0x7f07a0a14206 in _PyObject_MakeTpCall Objects/call.c:240
    #25 0x7f07a098d20a in _PyEval_EvalFrameDefault Python/bytecodes.c:2715
    #26 0x7f07a0a14e6c in _PyFunction_Vectorcall Objects/call.c:419
    #27 0x7f07a0a14e6c in _PyObject_FastCallDictTstate Objects/call.c:144
    #28 0x7f07a0a14e6c in _PyObject_Call_Prepend Objects/call.c:508
    #29 0x7f07a0ac3381 in slot_tp_call Objects/typeobject.c:8791
    #30 0x7f07a0a14206 in _PyObject_MakeTpCall Objects/call.c:240
    #31 0x7f07a098d20a in _PyEval_EvalFrameDefault Python/bytecodes.c:2715
    #32 0x7f07a0a14e6c in _PyFunction_Vectorcall Objects/call.c:419
    #33 0x7f07a0a14e6c in _PyObject_FastCallDictTstate Objects/call.c:144
    #34 0x7f07a0a14e6c in _PyObject_Call_Prepend Objects/call.c:508
    #35 0x7f07a0ac3381 in slot_tp_call Objects/typeobject.c:8791
    #36 0x7f07a0a14206 in _PyObject_MakeTpCall Objects/call.c:240
    #37 0x7f07a098d20a in _PyEval_EvalFrameDefault Python/bytecodes.c:2715
    #38 0x7f07a0ae8f35 in PyEval_EvalCode Python/ceval.c:580
    #39 0x7f07a0ae7a3c in builtin_exec_impl Python/bltinmodule.c:1093
    #40 0x7f07a0ae7a3c in builtin_exec Python/clinic/bltinmodule.c.h:543
    #41 0x7f07a0a345a2 in cfunction_vectorcall_FASTCALL_KEYWORDS Objects/methodobject.c:438
    #42 0x7f07a0a14532 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:92
    #43 0x7f07a0a14532 in PyObject_Vectorcall Objects/call.c:325
    #44 0x7f07a098d20a in _PyEval_EvalFrameDefault Python/bytecodes.c:2715
    #45 0x7f07a0ae8f35 in PyEval_EvalCode Python/ceval.c:580
    #46 0x7f07a0b09f76 in run_eval_code_obj Python/pythonrun.c:1757
    #47 0x7f07a0b09aaa in run_mod Python/pythonrun.c:1778
    #48 0x7f07a0b099f1 in pyrun_file Python/pythonrun.c:1674
    #49 0x7f07a0b09852 in _PyRun_SimpleFileObject Python/pythonrun.c:459
    #50 0x7f07a0b09667 in _PyRun_AnyFileObject Python/pythonrun.c:78
    #51 0x7f07a0b12943 in pymain_run_file_obj Modules/main.c:361
    #52 0x7f07a0b12943 in pymain_run_file Modules/main.c:380
    #53 0x7f07a0b12943 in pymain_run_python Modules/main.c:634
    #54 0x7f07a0b12943 in Py_RunMain Modules/main.c:714
    #55 0x7f07a0b1243a in Py_BytesMain Modules/main.c:768
    #56 0x7f07a042a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
    #57 0x7f07a042a28a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: a4a7992a8e66555c8141ab2a08a8465ff6e0ea65)
    #58 0x558976af7094 in _start (/opt/hostedtoolcache/Python/3.12.15/x64/bin/python3.12+0x1094) (BuildId: d664fd041bd9df9902c326eb80717fa04325aaaa)

0x50e000e8e350 is located 16 bytes inside of 152-byte region [0x50e000e8e340,0x50e000e8e3d8)
allocated by thread T0 here:
    #0 0x7f07a10fd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f07a0a7c2fc in gc_alloc Modules/gcmodule.c:2330
    #2 0x7f07a0a7c2fc in _PyObject_GC_NewVar Modules/gcmodule.c:2364

SUMMARY: AddressSanitizer: bad-free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52 in free
==2637==ABORTING

See https://github.com/msgspec/msgspec/actions/runs/38243375356/job/114791328508

Now it is properly cleaned.

@sobolevn sobolevn changed the title Fix Meta(pattern=..) leak Fix Meta(pattern=..) memory leak / corruption Oct 12, 2026
@sobolevn
sobolevn requested a review from provinzkraut October 12, 2026 12:15
@sobolevn
sobolevn marked this pull request as ready for review October 12, 2026 12:15
@sobolevn
sobolevn added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 4f7363d Oct 12, 2026
25 checks passed
@sobolevn
sobolevn deleted the fix-meta-leak branch October 12, 2026 15:25
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