[Python-checkins] commit of r41486 - in python/trunk: Misc Python

neal.norwitz@python.org neal.norwitz at python.org
Mon Nov 21 00:58:39 CET 2005


Author: neal.norwitz
Date: Mon Nov 21 00:58:38 2005
New Revision: 41486
Modified:
 python/trunk/Misc/README.valgrind
 python/trunk/Python/ast.c
 python/trunk/Python/compile.c
 python/trunk/Python/modsupport.c
Log:
Fix a few more memory leaks
Document more info about the benefits of configuring without 
pymalloc when running valgrind
Modified: python/trunk/Misc/README.valgrind
==============================================================================
--- python/trunk/Misc/README.valgrind	(original)
+++ python/trunk/Misc/README.valgrind	Mon Nov 21 00:58:38 2005
@@ -12,6 +12,19 @@
 * Uncomment the lines in Misc/valgrind-python.supp that
 suppress the warnings for PyObject_Free and PyObject_Realloc
 
+If you want to use Valgrind more effectively and catch even more
+memory leaks, you will need to configure python --without-pymalloc.
+PyMalloc allocates a few blocks in big chunks and most object
+allocations don't call malloc, they use chunks doled about by PyMalloc
+from the big blocks. This means Valgrind can't detect
+many allocations (and frees), except for those that are forwarded
+to the system malloc. Note: configuring python --without-pymalloc
+makes Python run much slower, especially when running under Valgrind.
+You may need to run the tests in batches under Valgrind to keep
+the memory usage down to allow the tests to complete. It seems to take
+about 5 times longer to run --without-pymalloc.
+
+
 Details:
 --------
 Python uses its own small-object allocation scheme on top of malloc,
@@ -21,7 +34,8 @@
 Starting with Python 2.3, PyMalloc is used by default. You can disable
 PyMalloc when configuring python by adding the --without-pymalloc option.
 If you disable PyMalloc, most of the information in this document and
-the supplied suppressions file will not be useful.
+the supplied suppressions file will not be useful. As discussed above,
+disabling PyMalloc can catch more problems.
 
 If you use valgrind on a default build of Python, you will see
 many errors like:
Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Mon Nov 21 00:58:38 2005
@@ -1054,8 +1054,12 @@
 return NULL;
 }
 
-	if (asdl_seq_LEN(t) == 1)
+	if (asdl_seq_LEN(t) == 1) {
 	 lc = comprehension(asdl_seq_GET(t, 0), expression, NULL);
+	 /* only free the sequence since we grabbed element 0 above */
+	 if (lc)
+	 asdl_seq_free(t); /* ok */
+	}
 	else
 	 lc = comprehension(Tuple(t, Store, LINENO(ch)), expression, NULL);
 
@@ -1222,9 +1226,13 @@
 return NULL;
 }
 
- if (asdl_seq_LEN(t) == 1)
+ if (asdl_seq_LEN(t) == 1) {
 ge = comprehension(asdl_seq_GET(t, 0), expression,
 NULL);
+	 /* only free the sequence since we grabbed element 0 above */
+	 if (ge)
+	 asdl_seq_free(t); /* ok */
+	}
 else
 ge = comprehension(Tuple(t, Store, LINENO(ch)),
 expression, NULL);
Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c	(original)
+++ python/trunk/Python/compile.c	Mon Nov 21 00:58:38 2005
@@ -2384,7 +2384,10 @@
 			dot = strchr(src, '.');
 			attr = PyString_FromStringAndSize(src, 
 					 dot ? dot - src : strlen(src));
+			if (!attr)
+				return -1;
 			ADDOP_O(c, LOAD_ATTR, attr, names);
+			Py_DECREF(attr);
 			src = dot + 1;
 		}
 	}
Modified: python/trunk/Python/modsupport.c
==============================================================================
--- python/trunk/Python/modsupport.c	(original)
+++ python/trunk/Python/modsupport.c	Mon Nov 21 00:58:38 2005
@@ -82,6 +82,7 @@
 			}
 			Py_DECREF(v);
 		}
+		Py_DECREF(n);
 	}
 	if (doc != NULL) {
 		v = PyString_FromString(doc);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /