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
d9c6564f
Commit
d9c6564f
authored
Mar 19, 2019
by
stratakis
Committed by
Victor Stinner
Mar 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-18368: Fix memory leaks in PyOS_StdioReadline() when realloc() fails (GH-12334)
(cherry picked from commit
9ae513ca
)
parent
0f68d4af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
Misc/NEWS.d/next/Core and Builtins/2019-03-14-17-30-46.bpo-18368.WXaHAo.rst
...ore and Builtins/2019-03-14-17-30-46.bpo-18368.WXaHAo.rst
+1
-0
Parser/myreadline.c
Parser/myreadline.c
+17
-5
No files found.
Misc/NEWS.d/next/Core and Builtins/2019-03-14-17-30-46.bpo-18368.WXaHAo.rst
0 → 100644
View file @
d9c6564f
PyOS_StdioReadline() no longer leaks memory when realloc() fails.
Parser/myreadline.c
View file @
d9c6564f
...
...
@@ -108,7 +108,7 @@ char *
PyOS_StdioReadline
(
FILE
*
sys_stdin
,
FILE
*
sys_stdout
,
char
*
prompt
)
{
size_t
n
;
char
*
p
;
char
*
p
,
*
pr
;
n
=
100
;
if
((
p
=
(
char
*
)
PyMem_MALLOC
(
n
))
==
NULL
)
return
NULL
;
...
...
@@ -140,17 +140,29 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
n
=
strlen
(
p
);
while
(
n
>
0
&&
p
[
n
-
1
]
!=
'\n'
)
{
size_t
incr
=
n
+
2
;
p
=
(
char
*
)
PyMem_REALLOC
(
p
,
n
+
incr
);
if
(
p
==
NULL
)
return
NULL
;
if
(
incr
>
INT_MAX
)
{
PyMem_FREE
(
p
);
PyErr_SetString
(
PyExc_OverflowError
,
"input line too long"
);
return
NULL
;
}
pr
=
(
char
*
)
PyMem_REALLOC
(
p
,
n
+
incr
);
if
(
pr
==
NULL
)
{
PyMem_FREE
(
p
);
PyErr_NoMemory
();
return
NULL
;
}
p
=
pr
;
if
(
my_fgets
(
p
+
n
,
(
int
)
incr
,
sys_stdin
)
!=
0
)
break
;
n
+=
strlen
(
p
+
n
);
}
return
(
char
*
)
PyMem_REALLOC
(
p
,
n
+
1
);
pr
=
(
char
*
)
PyMem_REALLOC
(
p
,
n
+
1
);
if
(
pr
==
NULL
)
{
PyMem_FREE
(
p
);
PyErr_NoMemory
();
return
NULL
;
}
return
pr
;
}
...
...
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