mirror of
https://github.com/python/cpython.git
synced 2025-11-21 11:19:43 +00:00
Fix some refleaks (and format/error checking)
This commit is contained in:
parent
247b5154ac
commit
908c871eeb
1 changed files with 13 additions and 9 deletions
|
|
@ -1160,9 +1160,9 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyUnicode_Check(Zreplacement)) {
|
if (PyUnicode_Check(Zreplacement)) {
|
||||||
PyObject *tmp = PyUnicode_AsUTF8String(Zreplacement);
|
PyObject *tmp = PyUnicode_AsUTF8String(Zreplacement);
|
||||||
|
Py_DECREF(Zreplacement);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_DECREF(Zreplacement);
|
|
||||||
Zreplacement = tmp;
|
Zreplacement = tmp;
|
||||||
}
|
}
|
||||||
if (!PyBytes_Check(Zreplacement)) {
|
if (!PyBytes_Check(Zreplacement)) {
|
||||||
|
|
@ -1208,12 +1208,11 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
||||||
|
|
||||||
assert(object && format && timetuple);
|
assert(object && format && timetuple);
|
||||||
assert(PyUnicode_Check(format));
|
assert(PyUnicode_Check(format));
|
||||||
/* Convert the input format to a C string and size */
|
/* Convert the input format to a C string and size */
|
||||||
pin = PyUnicode_AsString(format);
|
pin = PyUnicode_AsString(format);
|
||||||
if(!pin)
|
if (!pin)
|
||||||
return NULL;
|
return NULL;
|
||||||
flen = PyUnicode_GetSize(format);
|
flen = PyUnicode_GetSize(format);
|
||||||
|
|
||||||
|
|
||||||
/* Give up if the year is before 1900.
|
/* Give up if the year is before 1900.
|
||||||
* Python strftime() plays games with the year, and different
|
* Python strftime() plays games with the year, and different
|
||||||
|
|
@ -1335,11 +1334,16 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
||||||
if (PyBytes_Resize(newfmt, usednew) < 0)
|
if (PyBytes_Resize(newfmt, usednew) < 0)
|
||||||
goto Done;
|
goto Done;
|
||||||
{
|
{
|
||||||
|
PyObject *format;
|
||||||
PyObject *time = PyImport_ImportModule("time");
|
PyObject *time = PyImport_ImportModule("time");
|
||||||
if (time == NULL)
|
if (time == NULL)
|
||||||
goto Done;
|
goto Done;
|
||||||
result = PyObject_CallMethod(time, "strftime", "OO",
|
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
|
||||||
PyUnicode_FromString(PyBytes_AS_STRING(newfmt)), timetuple);
|
if (format != NULL) {
|
||||||
|
result = PyObject_CallMethod(time, "strftime", "OO",
|
||||||
|
format, timetuple);
|
||||||
|
Py_DECREF(format);
|
||||||
|
}
|
||||||
Py_DECREF(time);
|
Py_DECREF(time);
|
||||||
}
|
}
|
||||||
Done:
|
Done:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue