Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4830f581
Commit
4830f581
authored
Mar 21, 2017
by
Xiang Zhang
Committed by
GitHub
Mar 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29849: fix a memory leak in import_from (GH-712)
parent
05f53735
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
Misc/NEWS
Misc/NEWS
+2
-0
Python/ceval.c
Python/ceval.c
+17
-10
No files found.
Misc/NEWS
View file @
4830f581
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-29849: Fix a memory leak when an ImportError is raised during from import.
- bpo-28856: Fix an oversight that %b format for bytes should support objects
follow the buffer protocol.
...
...
Python/ceval.c
View file @
4830f581
...
...
@@ -5024,7 +5024,7 @@ import_from(PyObject *v, PyObject *name)
{
PyObject
*
x
;
_Py_IDENTIFIER
(
__name__
);
PyObject
*
fullmodname
,
*
pkgname
,
*
pkgpath
,
*
pkgname_or_unknown
;
PyObject
*
fullmodname
,
*
pkgname
,
*
pkgpath
,
*
pkgname_or_unknown
,
*
errmsg
;
x
=
PyObject_GetAttr
(
v
,
name
);
if
(
x
!=
NULL
||
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
...
...
@@ -5039,6 +5039,7 @@ import_from(PyObject *v, PyObject *name)
}
fullmodname
=
PyUnicode_FromFormat
(
"%U.%U"
,
pkgname
,
name
);
if
(
fullmodname
==
NULL
)
{
Py_DECREF
(
pkgname
);
return
NULL
;
}
x
=
PyDict_GetItem
(
PyImport_GetModuleDict
(),
fullmodname
);
...
...
@@ -5063,17 +5064,23 @@ import_from(PyObject *v, PyObject *name)
if
(
pkgpath
==
NULL
||
!
PyUnicode_Check
(
pkgpath
))
{
PyErr_Clear
();
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R from %R (unknown location)"
,
name
,
pkgname_or_unknown
),
pkgname
,
NULL
);
}
else
{
PyErr_SetImportError
(
PyUnicode_FromFormat
(
"cannot import name %R from %R (%S)"
,
name
,
pkgname_or_unknown
,
pkgpath
),
pkgname
,
pkgpath
);
errmsg
=
PyUnicode_FromFormat
(
"cannot import name %R from %R (unknown location)"
,
name
,
pkgname_or_unknown
);
/* NULL check for errmsg done by PyErr_SetImportError. */
PyErr_SetImportError
(
errmsg
,
pkgname
,
NULL
);
}
else
{
errmsg
=
PyUnicode_FromFormat
(
"cannot import name %R from %R (%S)"
,
name
,
pkgname_or_unknown
,
pkgpath
);
/* NULL check for errmsg done by PyErr_SetImportError. */
PyErr_SetImportError
(
errmsg
,
pkgname
,
pkgpath
);
}
Py_XDECREF
(
errmsg
);
Py_XDECREF
(
pkgname_or_unknown
);
Py_XDECREF
(
pkgpath
);
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment