diff options
-rw-r--r-- | Lib/decimal.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 8 | ||||
-rw-r--r-- | Misc/valgrind-python.supp | 33 | ||||
-rw-r--r-- | Modules/_ctypes/stgdict.c | 3 | ||||
-rw-r--r-- | Modules/_fileio.c | 1 | ||||
-rw-r--r-- | Modules/signalmodule.c | 3 | ||||
-rw-r--r-- | Objects/stringlib/formatter.h | 5 | ||||
-rw-r--r-- | Objects/structseq.c | 20 | ||||
-rw-r--r-- | Python/getargs.c | 10 |
9 files changed, 73 insertions, 12 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 88cc5cd..7fb9c7b 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -5147,7 +5147,7 @@ def _dlog10(c, e, p): log_tenpower = f*M # exact else: log_d = 0 # error < 2.31 - log_tenpower = div_nearest(f, 10**-p) # error < 0.5 + log_tenpower = _div_nearest(f, 10**-p) # error < 0.5 return _div_nearest(log_tenpower+log_d, 100) @@ -12,6 +12,14 @@ What's New in Python 3.0 release candidate 1 Core and Builtins ----------------- +- Fix crashes on memory allocation failure found with failmalloc. + +- Fix memory leaks found with valgrind and update suppressions file. + +- Fix compiler warnings in opt mode which would lead to invalid memory reads. + +- Fix problem using wrong name in decimal module reported by pychecker. + - Issue #3650: Fixed a reference leak in bytes.split('x'). Library diff --git a/Misc/valgrind-python.supp b/Misc/valgrind-python.supp index 7fb8dc7..319e5d1 100644 --- a/Misc/valgrind-python.supp +++ b/Misc/valgrind-python.supp @@ -47,6 +47,39 @@ # { + Suppress leaking the GIL. Happens once per process, see comment in ceval.c. + Memcheck:Leak + fun:malloc + fun:PyThread_allocate_lock + fun:PyEval_InitThreads +} + +{ + Suppress leaking the GIL after a fork. + Memcheck:Leak + fun:malloc + fun:PyThread_allocate_lock + fun:PyEval_ReInitThreads +} + +{ + Suppress leaking the autoTLSkey. This looks like it shouldn't leak though. + Memcheck:Leak + fun:malloc + fun:PyThread_create_key + fun:_PyGILState_Init + fun:Py_InitializeEx + fun:Py_Main +} + +{ + Hmmm, is this a real leak or like the GIL? + Memcheck:Leak + fun:malloc + fun:PyThread_ReInitTLS +} + +{ Handle PyMalloc confusing valgrind (possibly leaked) Memcheck:Leak fun:realloc diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index aac073f..7db3e0f 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -408,6 +408,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ffi_ofs = 0; } + assert(stgdict->format == NULL); if (isStruct && !isPacked) { stgdict->format = alloc_format_string(NULL, "T{"); } else { @@ -527,7 +528,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) #undef realdict if (isStruct && !isPacked) { + char *ptr = stgdict->format; stgdict->format = alloc_format_string(stgdict->format, "}"); + PyMem_Free(ptr); if (stgdict->format == NULL) return -1; } diff --git a/Modules/_fileio.c b/Modules/_fileio.c index f0c8fed..ec123e8 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -278,6 +278,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) ret = -1; done: + PyMem_Free(name); return ret; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index e190429..8860b39 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -796,7 +796,8 @@ PyInit_signal(void) #if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER) ItimerError = PyErr_NewException("signal.ItimerError", PyExc_IOError, NULL); - PyDict_SetItemString(d, "ItimerError", ItimerError); + if (ItimerError != NULL) + PyDict_SetItemString(d, "ItimerError", ItimerError); #endif if (PyErr_Occurred()) { diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h index b964435..aa99123 100644 --- a/Objects/stringlib/formatter.h +++ b/Objects/stringlib/formatter.h @@ -641,7 +641,10 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format, /* We know this can't fail, since we've already reserved enough space. */ STRINGLIB_CHAR *pstart = p + n_leading_chars; - int r = STRINGLIB_GROUPING(pstart, n_digits, n_digits, +#ifndef NDEBUG + int r = +#endif + STRINGLIB_GROUPING(pstart, n_digits, n_digits, spec.n_total+n_grouping_chars-n_leading_chars, NULL, 0); assert(r); diff --git a/Objects/structseq.c b/Objects/structseq.c index 091370c..808f938 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -32,6 +32,8 @@ PyStructSequence_New(PyTypeObject *type) PyStructSequence *obj; obj = PyObject_New(PyStructSequence, type); + if (obj == NULL) + return NULL; Py_SIZE(obj) = VISIBLE_SIZE_TP(type); return (PyObject*) obj; @@ -522,10 +524,16 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc) Py_INCREF(type); dict = type->tp_dict; - PyDict_SetItemString(dict, visible_length_key, - PyLong_FromLong((long) desc->n_in_sequence)); - PyDict_SetItemString(dict, real_length_key, - PyLong_FromLong((long) n_members)); - PyDict_SetItemString(dict, unnamed_fields_key, - PyLong_FromLong((long) n_unnamed_members)); +#define SET_DICT_FROM_INT(key, value) \ + do { \ + PyObject *v = PyLong_FromLong((long) value); \ + if (v != NULL) { \ + PyDict_SetItemString(dict, key, v); \ + Py_DECREF(v); \ + } \ + } while (0) + + SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence); + SET_DICT_FROM_INT(real_length_key, n_members); + SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members); } diff --git a/Python/getargs.c b/Python/getargs.c index cf4444c..b7beb37 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1354,7 +1354,7 @@ convertbuffer(PyObject *arg, void **p, char **errmsg) /* XXX for 3.x, getbuffer and convertbuffer can probably be merged again. */ static int -getbuffer(PyObject *arg, Py_buffer *view, char**errmsg) +getbuffer(PyObject *arg, Py_buffer *view, char **errmsg) { void *buf; Py_ssize_t count; @@ -1364,8 +1364,10 @@ getbuffer(PyObject *arg, Py_buffer *view, char**errmsg) return -1; } if (pb->bf_getbuffer) { - if (pb->bf_getbuffer(arg, view, 0) < 0) + if (pb->bf_getbuffer(arg, view, 0) < 0) { + *errmsg = "convertible to a buffer"; return -1; + } if (!PyBuffer_IsContiguous(view, 'C')) { *errmsg = "contiguous buffer"; return -1; @@ -1374,8 +1376,10 @@ getbuffer(PyObject *arg, Py_buffer *view, char**errmsg) } count = convertbuffer(arg, &buf, errmsg); - if (count < 0) + if (count < 0) { + *errmsg = "convertible to a buffer"; return count; + } PyBuffer_FillInfo(view, NULL, buf, count, 1, 0); return 0; } |