[Python-3000-checkins] r66007 - in python/branches/py3k: Lib/decimal.py Misc/NEWS Misc/valgrind-python.supp Modules/_ctypes/stgdict.c Modules/_fileio.c Modules/signalmodule.c Objects/stringlib/formatter.h Objects/structseq.c Python/getargs.c

neal.norwitz python-3000-checkins at python.org
Sun Aug 24 07:48:10 CEST 2008


Author: neal.norwitz
Date: Sun Aug 24 07:48:10 2008
New Revision: 66007

Log:
Merged revisions 66006 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes)

........
  r66006 | neal.norwitz | 2008-08-23 22:04:52 -0700 (Sat, 23 Aug 2008) | 25 lines
  
  Fix:
   * crashes on memory allocation failure found with failmalloc
   * memory leaks found with valgrind
   * compiler warnings in opt mode which would lead to invalid memory reads
   * problem using wrong name in decimal module reported by pychecker
  
  Update the valgrind suppressions file with new leaks that are small/one-time
  leaks we don't care about (ie, they are too hard to fix).
  
  TBR=barry
  TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes)
    in opt mode:
    valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
      ./python -E -tt ./Lib/test/regrtest.py -uall,-bsddb,-compiler \
                          -x test_logging test_ssl test_multiprocessing
    valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
      ./python -E -tt ./Lib/test/regrtest.py test_multiprocessing
    for i in `seq 1 4000` ; do
      LD_PRELOAD=~/local/lib/libfailmalloc.so FAILMALLOC_INTERVAL=$i \
          ./python -c pass
    done
  
  At least some of these fixes should probably be backported to 2.5.
........


Modified:
   python/branches/py3k/Lib/decimal.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Misc/valgrind-python.supp
   python/branches/py3k/Modules/_ctypes/stgdict.c
   python/branches/py3k/Modules/_fileio.c
   python/branches/py3k/Modules/signalmodule.c
   python/branches/py3k/Objects/stringlib/formatter.h
   python/branches/py3k/Objects/structseq.c
   python/branches/py3k/Python/getargs.c

Modified: python/branches/py3k/Lib/decimal.py
==============================================================================
--- python/branches/py3k/Lib/decimal.py	(original)
+++ python/branches/py3k/Lib/decimal.py	Sun Aug 24 07:48:10 2008
@@ -5147,7 +5147,7 @@
         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)
 

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Aug 24 07:48:10 2008
@@ -12,6 +12,14 @@
 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

Modified: python/branches/py3k/Misc/valgrind-python.supp
==============================================================================
--- python/branches/py3k/Misc/valgrind-python.supp	(original)
+++ python/branches/py3k/Misc/valgrind-python.supp	Sun Aug 24 07:48:10 2008
@@ -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

Modified: python/branches/py3k/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/py3k/Modules/_ctypes/stgdict.c	Sun Aug 24 07:48:10 2008
@@ -408,6 +408,7 @@
 		ffi_ofs = 0;
 	}
 
+	assert(stgdict->format == NULL);
 	if (isStruct && !isPacked) {
 		stgdict->format = alloc_format_string(NULL, "T{");
 	} else {
@@ -527,7 +528,9 @@
 #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;
 	}

Modified: python/branches/py3k/Modules/_fileio.c
==============================================================================
--- python/branches/py3k/Modules/_fileio.c	(original)
+++ python/branches/py3k/Modules/_fileio.c	Sun Aug 24 07:48:10 2008
@@ -278,6 +278,7 @@
 	ret = -1;
 
  done:
+	PyMem_Free(name);
 	return ret;
 }
 

Modified: python/branches/py3k/Modules/signalmodule.c
==============================================================================
--- python/branches/py3k/Modules/signalmodule.c	(original)
+++ python/branches/py3k/Modules/signalmodule.c	Sun Aug 24 07:48:10 2008
@@ -796,7 +796,8 @@
 #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()) {

Modified: python/branches/py3k/Objects/stringlib/formatter.h
==============================================================================
--- python/branches/py3k/Objects/stringlib/formatter.h	(original)
+++ python/branches/py3k/Objects/stringlib/formatter.h	Sun Aug 24 07:48:10 2008
@@ -641,7 +641,10 @@
 	    /* 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);

Modified: python/branches/py3k/Objects/structseq.c
==============================================================================
--- python/branches/py3k/Objects/structseq.c	(original)
+++ python/branches/py3k/Objects/structseq.c	Sun Aug 24 07:48:10 2008
@@ -32,6 +32,8 @@
 	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 @@
 	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);
 }

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Sun Aug 24 07:48:10 2008
@@ -1354,7 +1354,7 @@
 /* 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 @@
 		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 @@
 	}
 
 	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;
 }


More information about the Python-3000-checkins mailing list