Skip to content

Commit 9082da2

Browse files
jgarzikclaude
andcommitted
Fix CALL_FUNCTION_EX double-free on callee exception
When fn(*args) raised an exception, eval_exception_unwind freed the cfex_temp_pending buffer, then op_call_function_ex tried to free it again. Fix: clear cfex_temp_pending before the call so exception unwind doesn't free it; the normal cleanup path frees it instead. This fixes assertRaises(exc, fn, *args) crashing - a major blocker for importing real CPython tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9e19af7 commit 9082da2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/opcodes_call.asm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ DEF_FUNC op_call_function_ex
557557
.cfex_extract_done:
558558
mov rsi, [rbp - CFX_TEMP] ; use temp buffer as args
559559
.cfex_args_ready:
560+
; Clear cfex_temp_pending BEFORE the call, so exception unwind
561+
; won't free it (we free it ourselves in the normal path below).
562+
mov qword [rel cfex_temp_pending], 0
560563
mov rdx, [rbp - CFX_ARGS]
561564
mov rdx, [rdx + PyVarObject.ob_size]
562565
mov rdi, [rbp - CFX_FUNC]
@@ -569,7 +572,6 @@ DEF_FUNC op_call_function_ex
569572
mov rdi, [rbp - CFX_TEMP]
570573
test rdi, rdi
571574
jz .cfex_cleanup
572-
mov qword [rel cfex_temp_pending], 0 ; clear before freeing
573575
push rax
574576
push rdx
575577
call ap_free

0 commit comments

Comments
 (0)