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
ae1f0127
Commit
ae1f0127
authored
Aug 17, 2018
by
Sergey Fedoseev
Committed by
Serhiy Storchaka
Aug 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34395: Fix memory leaks caused by incautious usage of PyMem_Realloc(). (GH-8785)
parent
2ec530cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
32 deletions
+24
-32
Modules/_csv.c
Modules/_csv.c
+24
-32
No files found.
Modules/_csv.c
View file @
ae1f0127
...
...
@@ -565,24 +565,23 @@ parse_save_field(ReaderObj *self)
static
int
parse_grow_buff
(
ReaderObj
*
self
)
{
if
(
self
->
field_size
==
0
)
{
self
->
field_size
=
4096
;
if
(
self
->
field
!=
NULL
)
PyMem_Free
(
self
->
field
);
self
->
field
=
PyMem_Malloc
(
self
->
field_size
);
}
else
{
if
(
self
->
field_size
>
INT_MAX
/
2
)
{
PyErr_NoMemory
();
return
0
;
}
self
->
field_size
*=
2
;
self
->
field
=
PyMem_Realloc
(
self
->
field
,
self
->
field_size
);
unsigned
field_size_new
;
char
*
field_new
;
assert
((
unsigned
)
self
->
field_size
<=
INT_MAX
);
field_size_new
=
self
->
field_size
?
2
*
(
unsigned
)
self
->
field_size
:
4096
;
if
(
field_size_new
>
INT_MAX
)
{
PyErr_NoMemory
();
return
0
;
}
if
(
self
->
field
==
NULL
)
{
field_new
=
(
char
*
)
PyMem_Realloc
(
self
->
field
,
field_size_new
);
if
(
field_new
==
NULL
)
{
PyErr_NoMemory
();
return
0
;
}
self
->
field
=
field_new
;
self
->
field_size
=
(
int
)
field_size_new
;
return
1
;
}
...
...
@@ -1088,31 +1087,24 @@ join_append_data(WriterObj *self, char *field, int quote_empty,
static
int
join_check_rec_size
(
WriterObj
*
self
,
int
rec_len
)
{
unsigned
rec_size_new
;
char
*
rec_new
;
if
(
rec_len
<
0
||
rec_len
>
INT_MAX
-
MEM_INCR
)
{
PyErr_NoMemory
();
return
0
;
}
assert
(
rec_len
>=
0
);
if
(
rec_len
>
self
->
rec_size
)
{
if
(
self
->
rec_size
==
0
)
{
self
->
rec_size
=
(
rec_len
/
MEM_INCR
+
1
)
*
MEM_INCR
;
if
(
self
->
rec
!=
NULL
)
PyMem_Free
(
self
->
rec
);
self
->
rec
=
PyMem_Malloc
(
self
->
rec_size
);
}
else
{
char
*
old_rec
=
self
->
rec
;
self
->
rec_size
=
(
rec_len
/
MEM_INCR
+
1
)
*
MEM_INCR
;
self
->
rec
=
PyMem_Realloc
(
self
->
rec
,
self
->
rec_size
);
if
(
self
->
rec
==
NULL
)
PyMem_Free
(
old_rec
);
rec_size_new
=
(
unsigned
)(
rec_len
/
MEM_INCR
+
1
)
*
MEM_INCR
;
if
(
rec_size_new
>
INT_MAX
)
{
PyErr_NoMemory
();
return
0
;
}
if
(
self
->
rec
==
NULL
)
{
rec_new
=
(
char
*
)
PyMem_Realloc
(
self
->
rec
,
rec_size_new
);
if
(
rec_new
==
NULL
)
{
PyErr_NoMemory
();
return
0
;
}
self
->
rec
=
rec_new
;
self
->
rec_size
=
(
int
)
rec_size_new
;
}
return
1
;
}
...
...
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