summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-31 20:23:49 (GMT)
committerGitHub <noreply@github.com>2017-03-31 20:23:49 (GMT)
commit7d5d13d8d003ae5b62bb8c9ef1d1f310eaabc506 (patch)
tree0351bc800a0436804e45c36120d79b26578c9ff6 /Modules
parent0a17e584461b14ff65ec287048f53911dbb22222 (diff)
downloadcpython-7d5d13d8d003ae5b62bb8c9ef1d1f310eaabc506.zip
cpython-7d5d13d8d003ae5b62bb8c9ef1d1f310eaabc506.tar.gz
cpython-7d5d13d8d003ae5b62bb8c9ef1d1f310eaabc506.tar.bz2
bpo-29953: Fix memory leaks in the replace() method of datetime and t… (#933)
objects when pass out of bound fold argument. (cherry picked from commit 314d6fca36a4eaa0541218431d14804fadec6488)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index c784d0f..c2ad9a2 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3926,16 +3926,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);
@@ -5019,17 +5019,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);