From d780fa7931d8ce94994827232d7cca79b0be3bf1 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 22 Jun 2020 00:39:28 -0700 Subject: [PATCH] bpo-41056: Fix a possible MemoryError leak within zoneinfo. (GH-21007) This was detected by our Coverity scan as a REVERSE_INULL issue. Automerge-Triggered-By: @gpshead --- .../next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst | 1 + Modules/_zoneinfo.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst new file mode 100644 index 00000000000..0439d82a50a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst @@ -0,0 +1 @@ +Fixed an instance where a MemoryError within the zoneinfo module might not be reported or not reported at its source. (found by Coverity) \ No newline at end of file diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index e8b28319993..a2883495fe7 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -278,13 +278,11 @@ zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw) instance = PyObject_CallMethod(weak_cache, "setdefault", "OO", key, tmp); - ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; - Py_DECREF(tmp); - if (instance == NULL) { return NULL; } + ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; } update_strong_cache(type, key, instance); @@ -1622,7 +1620,7 @@ parse_abbr(const char *const p, PyObject **abbr) } *abbr = PyUnicode_FromStringAndSize(str_start, str_end - str_start); - if (abbr == NULL) { + if (*abbr == NULL) { return -1; }