summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-27 04:58:38 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-27 04:58:38 (GMT)
commit908c871eeb1490c105d46c7a470201f39f2f89f8 (patch)
treef205de0fc8a6dbf8f529b5c450b9dab3c45fee18 /Modules
parent247b5154ac37c2069d48fc500f06f06ff6763fa1 (diff)
downloadcpython-908c871eeb1490c105d46c7a470201f39f2f89f8.zip
cpython-908c871eeb1490c105d46c7a470201f39f2f89f8.tar.gz
cpython-908c871eeb1490c105d46c7a470201f39f2f89f8.tar.bz2
Fix some refleaks (and format/error checking)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index e513910..70118d2 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1160,9 +1160,9 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
return NULL;
if (PyUnicode_Check(Zreplacement)) {
PyObject *tmp = PyUnicode_AsUTF8String(Zreplacement);
+ Py_DECREF(Zreplacement);
if (tmp == NULL)
return NULL;
- Py_DECREF(Zreplacement);
Zreplacement = tmp;
}
if (!PyBytes_Check(Zreplacement)) {
@@ -1208,12 +1208,11 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(object && format && timetuple);
assert(PyUnicode_Check(format));
- /* Convert the input format to a C string and size */
- pin = PyUnicode_AsString(format);
- if(!pin)
- return NULL;
- flen = PyUnicode_GetSize(format);
-
+ /* Convert the input format to a C string and size */
+ pin = PyUnicode_AsString(format);
+ if (!pin)
+ return NULL;
+ flen = PyUnicode_GetSize(format);
/* Give up if the year is before 1900.
* 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)
goto Done;
{
+ PyObject *format;
PyObject *time = PyImport_ImportModule("time");
if (time == NULL)
goto Done;
- result = PyObject_CallMethod(time, "strftime", "OO",
- PyUnicode_FromString(PyBytes_AS_STRING(newfmt)), timetuple);
+ format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
+ if (format != NULL) {
+ result = PyObject_CallMethod(time, "strftime", "OO",
+ format, timetuple);
+ Py_DECREF(format);
+ }
Py_DECREF(time);
}
Done: