Skip to content

py_loader: release PyObject_Str results in error print and error value - #921

Open
bhuvan-somisetty wants to merge 1 commit into
metacall:developfrom
bhuvan-somisetty:fix/py-loader-error-print-leak
Open

bhuvan-somisetty wants to merge 1 commit into
metacall:developfrom
bhuvan-somisetty:fix/py-loader-error-print-leak

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

First python leak from going through the valgrind CI with @viferga. PyObject_Str returns a new reference, but py_loader_impl_error_print never released type_str_obj and value_str_obj, and py_loader_impl_error_value_from_exception never released value_str_obj. So two strings leaked every time a python error got printed, and one more every time it was turned into a throwable. exception_create_const copies the strings, so it's safe to release them after.

Tested with ./docker-compose.sh test-memcheck (python only) and then MEMCHECK_TEST=python make memcheck inside the image. The definitely lost records coming from these two functions go from 7 to 0, metacall-python-fail-test goes from 629 to 0 bytes definitely lost and metacall-python-relative-path-test from 219 to 0, with no new invalid reads or frees. All 12 python tests still pass without valgrind. The rest of the python errors are mostly "possibly lost" from the interpreter itself, that needs the instrumented python so I left it for later.

py_loader_impl_error_print never released type_str_obj and
value_str_obj, and py_loader_impl_error_value_from_exception never
released value_str_obj. Both come from PyObject_Str so they are new
references, and they leaked every time a python error was handled.
exception_create_const copies the strings, so it is safe to release
them after creating the exception. Found with valgrind.

This branch has not been deployed

No deployments
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.

1 participant