#3205: bz2 iterator fails silently on MemoryError
diff --git a/Misc/NEWS b/Misc/NEWS
index cabee7f..c6c401f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #3205: When iterating over a BZ2File fails allocating memory, raise
+ a MemoryError rather than silently stop the iteration.
+
- Issue #1481296: Make long(float('nan')) and int(float('nan')) raise
ValueError consistently across platforms.
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 16201bd..3929219 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -416,6 +416,7 @@
return 0;
}
if ((f->f_buf = PyMem_Malloc(bufsize)) == NULL) {
+ PyErr_NoMemory();
return -1;
}
Py_BEGIN_ALLOW_THREADS