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
314d6fca
Commit
314d6fca
authored
Mar 31, 2017
by
Serhiy Storchaka
Committed by
GitHub
Mar 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29953: Fix memory leaks in the replace() method of datetime and time (#927)
objects when pass out of bound fold argument.
parent
06bb4873
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
11 deletions
+18
-11
Lib/test/datetimetester.py
Lib/test/datetimetester.py
+5
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_datetimemodule.c
Modules/_datetimemodule.c
+10
-11
No files found.
Lib/test/datetimetester.py
View file @
314d6fca
...
...
@@ -4313,6 +4313,11 @@ class TestLocalTimeDisambiguation(unittest.TestCase):
dt
=
dt
.
replace
(
fold
=
1
,
tzinfo
=
Eastern
)
self
.
assertEqual
(
t
.
replace
(
tzinfo
=
None
).
fold
,
1
)
self
.
assertEqual
(
dt
.
replace
(
tzinfo
=
None
).
fold
,
1
)
# Out of bounds.
with
self
.
assertRaises
(
ValueError
):
t
.
replace
(
fold
=
2
)
with
self
.
assertRaises
(
ValueError
):
dt
.
replace
(
fold
=
2
)
# Check that fold is a keyword-only argument
with
self
.
assertRaises
(
TypeError
):
t
.
replace
(
1
,
1
,
1
,
None
,
1
)
...
...
Misc/NEWS
View file @
314d6fca
...
...
@@ -301,6 +301,9 @@ Extension Modules
Library
-------
- bpo-29953: Fixed memory leaks in the replace() method of datetime and time
objects when pass out of bound fold argument.
- bpo-29942: Fix a crash in itertools.chain.from_iterable when encountering
long runs of empty iterables.
...
...
Modules/_datetimemodule.c
View file @
314d6fca
...
...
@@ -3937,16 +3937,16 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
time_kws
,
&
hh
,
&
mm
,
&
ss
,
&
us
,
&
tzinfo
,
&
fold
))
return
NULL
;
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
tuple
=
Py_BuildValue
(
"iiiiO"
,
hh
,
mm
,
ss
,
us
,
tzinfo
);
if
(
tuple
==
NULL
)
return
NULL
;
clone
=
time_new
(
Py_TYPE
(
self
),
tuple
,
NULL
);
if
(
clone
!=
NULL
)
{
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
TIME_SET_FOLD
(
clone
,
fold
);
}
Py_DECREF
(
tuple
);
...
...
@@ -5030,17 +5030,16 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
&
y
,
&
m
,
&
d
,
&
hh
,
&
mm
,
&
ss
,
&
us
,
&
tzinfo
,
&
fold
))
return
NULL
;
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
tuple
=
Py_BuildValue
(
"iiiiiiiO"
,
y
,
m
,
d
,
hh
,
mm
,
ss
,
us
,
tzinfo
);
if
(
tuple
==
NULL
)
return
NULL
;
clone
=
datetime_new
(
Py_TYPE
(
self
),
tuple
,
NULL
);
if
(
clone
!=
NULL
)
{
if
(
fold
!=
0
&&
fold
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"fold must be either 0 or 1"
);
return
NULL
;
}
DATE_SET_FOLD
(
clone
,
fold
);
}
Py_DECREF
(
tuple
);
...
...
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