Skip to content

Commit 4c3477b

Browse files
committed
moar fixes much refleaks wow
1 parent 4cc6905 commit 4c3477b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Python/bltinmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ builtin___lazy_import___impl(PyObject *module, PyObject *name,
328328
if (PyModule_Check(builtins)) {
329329
PyObject *builtins_dict = Py_XNewRef(PyModule_GetDict(builtins));
330330
if (builtins_dict == NULL) {
331+
Py_DECREF(builtins);
331332
PyErr_SetString(PyExc_AttributeError, "builtins module has no dict");
332333
return NULL;
333334
}

Python/ceval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,6 +3768,9 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
37683768
if (d->lz_attr != NULL) {
37693769
if (PyUnicode_Check(d->lz_attr)) {
37703770
PyObject *from = PyUnicode_FromFormat("%U.%U", d->lz_from, d->lz_attr);
3771+
if (from == NULL) {
3772+
return NULL;
3773+
}
37713774
ret = _PyLazyImport_New(d->lz_builtins, from, name);
37723775
Py_DECREF(from);
37733776
return ret;
@@ -3776,6 +3779,9 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
37763779
Py_ssize_t dot = PyUnicode_FindChar(d->lz_from, '.', 0, PyUnicode_GET_LENGTH(d->lz_from), 1);
37773780
if (dot >= 0) {
37783781
PyObject *from = PyUnicode_Substring(d->lz_from, 0, dot);
3782+
if (from == NULL) {
3783+
return NULL;
3784+
}
37793785
ret = _PyLazyImport_New(d->lz_builtins, from, name);
37803786
Py_DECREF(from);
37813787
return ret;

Python/import.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,9 +4351,10 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
43514351
if (filter != NULL) {
43524352
PyObject *modname;
43534353
if (PyDict_GetItemRef(globals, &_Py_ID(__name__), &modname) < 0) {
4354+
Py_DECREF(abs_name);
43544355
return NULL;
43554356
} else if (modname == NULL) {
4356-
modname = Py_None;
4357+
modname = Py_NewRef(Py_None);
43574358
}
43584359
PyObject *args[] = {modname, name, fromlist};
43594360
PyObject *res = PyObject_Vectorcall(
@@ -4363,12 +4364,17 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
43634364
NULL
43644365
);
43654366

4367+
Py_DECREF(modname);
4368+
43664369
if (res == NULL) {
43674370
Py_DECREF(abs_name);
43684371
return NULL;
43694372
}
43704373

4371-
if (!PyObject_IsTrue(res)) {
4374+
int is_true = PyObject_IsTrue(res);
4375+
Py_DECREF(res);
4376+
4377+
if (!is_true) {
43724378
Py_DECREF(abs_name);
43734379
return PyImport_ImportModuleLevelObject(
43744380
name, globals, locals, fromlist, level
@@ -4612,6 +4618,7 @@ _PyImport_ClearCore(PyInterpreterState *interp)
46124618
Py_CLEAR(interp->imports.lazy_modules);
46134619
Py_CLEAR(interp->imports.lazy_modules_set);
46144620
Py_CLEAR(interp->imports.lazy_importing_modules);
4621+
Py_CLEAR(interp->imports.lazy_imports_filter);
46154622
}
46164623

46174624
void

0 commit comments

Comments
 (0)