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
6e43d073
Commit
6e43d073
authored
Jul 05, 2019
by
Jeroen Demeyer
Committed by
Inada Naoki
Jul 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-37483: fix reference leak in _PyCodec_Lookup (GH-14600)
parent
1da44627
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
13 deletions
+14
-13
Python/codecs.c
Python/codecs.c
+14
-13
No files found.
Python/codecs.c
View file @
6e43d073
...
...
@@ -99,40 +99,38 @@ PyObject *normalizestring(const char *string)
PyObject
*
_PyCodec_Lookup
(
const
char
*
encoding
)
{
PyObject
*
result
,
*
v
;
Py_ssize_t
i
,
len
;
if
(
encoding
==
NULL
)
{
PyErr_BadArgument
();
goto
onError
;
return
NULL
;
}
PyInterpreterState
*
interp
=
_PyInterpreterState_GET_UNSAFE
();
if
(
interp
->
codec_search_path
==
NULL
&&
_PyCodecRegistry_Init
())
goto
onError
;
if
(
interp
->
codec_search_path
==
NULL
&&
_PyCodecRegistry_Init
())
{
return
NULL
;
}
/* Convert the encoding to a normalized Python string: all
characters are converted to lower case, spaces and hyphens are
replaced with underscores. */
v
=
normalizestring
(
encoding
);
if
(
v
==
NULL
)
goto
onError
;
PyObject
*
v
=
normalizestring
(
encoding
);
if
(
v
==
NULL
)
{
return
NULL
;
}
PyUnicode_InternInPlace
(
&
v
);
/* First, try to lookup the name in the registry dictionary */
result
=
PyDict_GetItemWithError
(
interp
->
codec_search_cache
,
v
);
PyObject
*
result
=
PyDict_GetItemWithError
(
interp
->
codec_search_cache
,
v
);
if
(
result
!=
NULL
)
{
Py_INCREF
(
result
);
Py_DECREF
(
v
);
return
result
;
}
else
if
(
PyErr_Occurred
())
{
Py_DECREF
(
v
);
return
NULL
;
goto
onError
;
}
/* Next, scan the search functions in order of registration */
len
=
PyList_Size
(
interp
->
codec_search_path
);
const
Py_ssize_t
len
=
PyList_Size
(
interp
->
codec_search_path
);
if
(
len
<
0
)
goto
onError
;
if
(
len
==
0
)
{
...
...
@@ -142,6 +140,7 @@ PyObject *_PyCodec_Lookup(const char *encoding)
goto
onError
;
}
Py_ssize_t
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
PyObject
*
func
;
...
...
@@ -175,9 +174,11 @@ PyObject *_PyCodec_Lookup(const char *encoding)
Py_DECREF
(
result
);
goto
onError
;
}
Py_DECREF
(
v
);
return
result
;
onError:
Py_DECREF
(
v
);
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