gh-146308: Fix error handling issues in _remote_debugging module (#146309)

This commit is contained in:
Pablo Galindo Salgado 2026-03-22 21:12:02 +00:00 committed by GitHub
parent b4e5bc2164
commit ae6adc9079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 85 additions and 19 deletions

View file

@ -110,6 +110,7 @@ cache_tlbc_array(RemoteUnwinderObject *unwinder, uintptr_t code_addr, uintptr_t
void *key = (void *)code_addr;
if (_Py_hashtable_set(unwinder->tlbc_cache, key, entry) < 0) {
tlbc_cache_entry_destroy(entry);
PyErr_NoMemory();
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to store TLBC entry in cache");
return 0; // Cache error
}
@ -408,7 +409,14 @@ parse_code_object(RemoteUnwinderObject *unwinder,
meta->addr_code_adaptive = real_address + (uintptr_t)unwinder->debug_offsets.code_object.co_code_adaptive;
if (unwinder && unwinder->code_object_cache && _Py_hashtable_set(unwinder->code_object_cache, key, meta) < 0) {
// Ownership of func/file/linetable was transferred to meta,
// so NULL them before destroying meta to prevent double-free
// in the error label's Py_XDECREF calls.
func = NULL;
file = NULL;
linetable = NULL;
cached_code_metadata_destroy(meta);
PyErr_NoMemory();
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to cache code metadata");
goto error;
}