Skip to content

Commit e66abb3

Browse files
committed
gh-87092: fix a few cases of incorrect error handling
1 parent 9db2db4 commit e66abb3

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

Python/compile.c

+23-9
Original file line numberDiff line numberDiff line change
@@ -6689,7 +6689,10 @@ insert_prefix_instructions(struct compiler_unit *u, basicblock *entryblock,
66896689
.i_loc = NO_LOCATION,
66906690
.i_target = NULL,
66916691
};
6692-
RETURN_IF_ERROR(_PyBasicblock_InsertInstruction(entryblock, ncellsused, &make_cell));
6692+
if (_PyBasicblock_InsertInstruction(entryblock, ncellsused, &make_cell) < 0) {
6693+
PyMem_RawFree(sorted);
6694+
return ERROR;
6695+
}
66936696
ncellsused += 1;
66946697
}
66956698
PyMem_RawFree(sorted);
@@ -6861,7 +6864,7 @@ optimize_and_assemble_code_unit(struct compiler_unit *u, PyObject *const_cache,
68616864
maxdepth, g.g_entryblock, nlocalsplus,
68626865
code_flags, filename);
68636866

6864-
error:
6867+
error:
68656868
Py_XDECREF(consts);
68666869
instr_sequence_fini(&optimized_instrs);
68676870
_PyCfgBuilder_Fini(&g);
@@ -6959,7 +6962,9 @@ instructions_to_instr_sequence(PyObject *instructions, instr_sequence *seq)
69596962

69606963
for (int i = 0; i < num_insts; i++) {
69616964
if (is_target[i]) {
6962-
RETURN_IF_ERROR(instr_sequence_use_label(seq, i));
6965+
if (instr_sequence_use_label(seq, i) < 0) {
6966+
goto error;
6967+
}
69636968
}
69646969
PyObject *item = PyList_GET_ITEM(instructions, i);
69656970
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 6) {
@@ -6997,10 +7002,14 @@ instructions_to_instr_sequence(PyObject *instructions, instr_sequence *seq)
69977002
if (PyErr_Occurred()) {
69987003
goto error;
69997004
}
7000-
RETURN_IF_ERROR(instr_sequence_addop(seq, opcode, oparg, loc));
7005+
if (instr_sequence_addop(seq, opcode, oparg, loc) < 0) {
7006+
goto error;
7007+
}
70017008
}
70027009
if (seq->s_used && !IS_TERMINATOR_OPCODE(seq->s_instrs[seq->s_used-1].i_opcode)) {
7003-
RETURN_IF_ERROR(instr_sequence_addop(seq, RETURN_VALUE, 0, NO_LOCATION));
7010+
if (instr_sequence_addop(seq, RETURN_VALUE, 0, NO_LOCATION) < 0) {
7011+
goto error;
7012+
}
70047013
}
70057014
PyMem_Free(is_target);
70067015
return SUCCESS;
@@ -7015,12 +7024,17 @@ instructions_to_cfg(PyObject *instructions, cfg_builder *g)
70157024
instr_sequence seq;
70167025
memset(&seq, 0, sizeof(instr_sequence));
70177026

7018-
RETURN_IF_ERROR(
7019-
instructions_to_instr_sequence(instructions, &seq));
7020-
7021-
RETURN_IF_ERROR(instr_sequence_to_cfg(&seq, g));
7027+
if (instructions_to_instr_sequence(instructions, &seq) < 0) {
7028+
goto error;
7029+
}
7030+
if (instr_sequence_to_cfg(&seq, g) < 0) {
7031+
goto error;
7032+
}
70227033
instr_sequence_fini(&seq);
70237034
return SUCCESS;
7035+
error:
7036+
instr_sequence_fini(&seq);
7037+
return ERROR;
70247038
}
70257039

70267040
static PyObject *

0 commit comments

Comments
 (0)