Skip to content

Commit a95d986

Browse files
bpo-33132: Fix reference counting issues in the compiler. (GH-6209)
1 parent 4ca0739 commit a95d986

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

Python/compile.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,9 +2909,7 @@ static int
29092909
compiler_from_import(struct compiler *c, stmt_ty s)
29102910
{
29112911
Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);
2912-
2913-
PyObject *names = PyTuple_New(n);
2914-
PyObject *level;
2912+
PyObject *level, *names;
29152913
static PyObject *empty_string;
29162914

29172915
if (!empty_string) {
@@ -2920,14 +2918,15 @@ compiler_from_import(struct compiler *c, stmt_ty s)
29202918
return 0;
29212919
}
29222920

2923-
if (!names)
2924-
return 0;
2925-
29262921
level = PyLong_FromLong(s->v.ImportFrom.level);
29272922
if (!level) {
2928-
Py_DECREF(names);
29292923
return 0;
29302924
}
2925+
ADDOP_N(c, LOAD_CONST, level, consts);
2926+
2927+
names = PyTuple_New(n);
2928+
if (!names)
2929+
return 0;
29312930

29322931
/* build up the names */
29332932
for (i = 0; i < n; i++) {
@@ -2938,16 +2937,12 @@ compiler_from_import(struct compiler *c, stmt_ty s)
29382937

29392938
if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
29402939
_PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__")) {
2941-
Py_DECREF(level);
29422940
Py_DECREF(names);
29432941
return compiler_error(c, "from __future__ imports must occur "
29442942
"at the beginning of the file");
29452943
}
2944+
ADDOP_N(c, LOAD_CONST, names, consts);
29462945

2947-
ADDOP_O(c, LOAD_CONST, level, consts);
2948-
Py_DECREF(level);
2949-
ADDOP_O(c, LOAD_CONST, names, consts);
2950-
Py_DECREF(names);
29512946
if (s->v.ImportFrom.module) {
29522947
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
29532948
}
@@ -2970,7 +2965,6 @@ compiler_from_import(struct compiler *c, stmt_ty s)
29702965
store_name = alias->asname;
29712966

29722967
if (!compiler_nameop(c, store_name, Store)) {
2973-
Py_DECREF(names);
29742968
return 0;
29752969
}
29762970
}
@@ -4739,19 +4733,18 @@ compiler_annassign(struct compiler *c, stmt_ty s)
47394733
if (s->v.AnnAssign.simple &&
47404734
(c->u->u_scope_type == COMPILER_SCOPE_MODULE ||
47414735
c->u->u_scope_type == COMPILER_SCOPE_CLASS)) {
4742-
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
4743-
if (!mangled) {
4744-
return 0;
4745-
}
47464736
if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
47474737
VISIT(c, annexpr, s->v.AnnAssign.annotation)
47484738
}
47494739
else {
47504740
VISIT(c, expr, s->v.AnnAssign.annotation);
47514741
}
47524742
ADDOP_NAME(c, LOAD_NAME, __annotations__, names);
4753-
ADDOP_O(c, LOAD_CONST, mangled, consts);
4754-
Py_DECREF(mangled);
4743+
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
4744+
if (!mangled) {
4745+
return 0;
4746+
}
4747+
ADDOP_N(c, LOAD_CONST, mangled, consts);
47554748
ADDOP(c, STORE_SUBSCR);
47564749
}
47574750
break;

0 commit comments

Comments
 (0)