summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2018-12-07 10:11:30 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-12-07 10:11:30 (GMT)
commit4c49da0cb7434c676d70b9ccf38aca82ac0d64a9 (patch)
treeaae3660f9a5bc462830107cf2311b2557898e268 /Python
parent3a521f0b6167628f975c773b56c7daf8d33d6f40 (diff)
downloadcpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.zip
cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.gz
cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.bz2
bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015)
Set MemoryError when appropriate, add missing failure checks, and fix some potential leaks.
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c7
-rw-r--r--Python/marshal.c5
-rw-r--r--Python/pystrtod.c3
3 files changed, 12 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 24d5843..8a305a8 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -4097,6 +4097,9 @@ parsenumber(struct compiling *c, const char *s)
}
/* Create a duplicate without underscores. */
dup = PyMem_Malloc(strlen(s) + 1);
+ if (dup == NULL) {
+ return PyErr_NoMemory();
+ }
end = dup;
for (; *s; s++) {
if (*s != '_') {
@@ -4325,8 +4328,10 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
len = expr_end - expr_start;
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
str = PyMem_RawMalloc(len + 3);
- if (str == NULL)
+ if (str == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
str[0] = '(';
memcpy(str+1, expr_start, len);
diff --git a/Python/marshal.c b/Python/marshal.c
index 21cdd60..52932af 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -670,11 +670,12 @@ r_string(Py_ssize_t n, RFILE *p)
p->buf_size = n;
}
else if (p->buf_size < n) {
- p->buf = PyMem_REALLOC(p->buf, n);
- if (p->buf == NULL) {
+ char *tmp = PyMem_REALLOC(p->buf, n);
+ if (tmp == NULL) {
PyErr_NoMemory();
return NULL;
}
+ p->buf = tmp;
p->buf_size = n;
}
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 98aa9ba..02a3fb5 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -398,6 +398,9 @@ _Py_string_to_number_with_underscores(
}
dup = PyMem_Malloc(orig_len + 1);
+ if (dup == NULL) {
+ return PyErr_NoMemory();
+ }
end = dup;
prev = '\0';
last = s + orig_len;