| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,19 @@ Misc/valgrind-python.supp. Second, you must do one of the following: | |||
| 12 | 12 | * Uncomment the lines in Misc/valgrind-python.supp that | |
| 13 | 13 | suppress the warnings for PyObject_Free and PyObject_Realloc | |
| 14 | 14 | ||
| 15 | + If you want to use Valgrind more effectively and catch even more | ||
| 16 | + memory leaks, you will need to configure python --without-pymalloc. | ||
| 17 | + PyMalloc allocates a few blocks in big chunks and most object | ||
| 18 | + allocations don't call malloc, they use chunks doled about by PyMalloc | ||
| 19 | + from the big blocks. This means Valgrind can't detect | ||
| 20 | + many allocations (and frees), except for those that are forwarded | ||
| 21 | + to the system malloc. Note: configuring python --without-pymalloc | ||
| 22 | + makes Python run much slower, especially when running under Valgrind. | ||
| 23 | + You may need to run the tests in batches under Valgrind to keep | ||
| 24 | + the memory usage down to allow the tests to complete. It seems to take | ||
| 25 | + about 5 times longer to run --without-pymalloc. | ||
| 26 | + | ||
| 27 | + | ||
| 15 | 28 | Details: | |
| 16 | 29 | -------- | |
| 17 | 30 | Python uses its own small-object allocation scheme on top of malloc, | |
@@ -21,7 +34,8 @@ Valgrind may show some unexpected results when PyMalloc is used. | |||
| 21 | 34 | Starting with Python 2.3, PyMalloc is used by default. You can disable | |
| 22 | 35 | PyMalloc when configuring python by adding the --without-pymalloc option. | |
| 23 | 36 | If you disable PyMalloc, most of the information in this document and | |
| 24 | - the supplied suppressions file will not be useful. | ||
| 37 | + the supplied suppressions file will not be useful. As discussed above, | ||
| 38 | + disabling PyMalloc can catch more problems. | ||
| 25 | 39 | ||
| 26 | 40 | If you use valgrind on a default build of Python, you will see | |
| 27 | 41 | many errors like: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1054,8 +1054,12 @@ ast_for_listcomp(struct compiling *c, const node *n) | |||
| 1054 | 1054 | return NULL; | |
| 1055 | 1055 | } | |
| 1056 | 1056 | ||
| 1057 | - if (asdl_seq_LEN(t) == 1) | ||
| 1057 | + if (asdl_seq_LEN(t) == 1) { | ||
| 1058 | 1058 | lc = comprehension(asdl_seq_GET(t, 0), expression, NULL); | |
| 1059 | + /* only free the sequence since we grabbed element 0 above */ | ||
| 1060 | + if (lc) | ||
| 1061 | + asdl_seq_free(t); /* ok */ | ||
| 1062 | + } | ||
| 1059 | 1063 | else | |
| 1060 | 1064 | lc = comprehension(Tuple(t, Store, LINENO(ch)), expression, NULL); | |
| 1061 | 1065 | ||
@@ -1222,9 +1226,13 @@ ast_for_genexp(struct compiling *c, const node *n) | |||
| 1222 | 1226 | return NULL; | |
| 1223 | 1227 | } | |
| 1224 | 1228 | ||
| 1225 | - if (asdl_seq_LEN(t) == 1) | ||
| 1229 | + if (asdl_seq_LEN(t) == 1) { | ||
| 1226 | 1230 | ge = comprehension(asdl_seq_GET(t, 0), expression, | |
| 1227 | 1231 | NULL); | |
| 1232 | + /* only free the sequence since we grabbed element 0 above */ | ||
| 1233 | + if (ge) | ||
| 1234 | + asdl_seq_free(t); /* ok */ | ||
| 1235 | + } | ||
| 1228 | 1236 | else | |
| 1229 | 1237 | ge = comprehension(Tuple(t, Store, LINENO(ch)), | |
| 1230 | 1238 | expression, NULL); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2384,7 +2384,10 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname) | |||
| 2384 | 2384 | dot = strchr(src, '.'); | |
| 2385 | 2385 | attr = PyString_FromStringAndSize(src, | |
| 2386 | 2386 | dot ? dot - src : strlen(src)); | |
| 2387 | + if (!attr) | ||
| 2388 | + return -1; | ||
| 2387 | 2389 | ADDOP_O(c, LOAD_ATTR, attr, names); | |
| 2390 | + Py_DECREF(attr); | ||
| 2388 | 2391 | src = dot + 1; | |
| 2389 | 2392 | } | |
| 2390 | 2393 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,6 +82,7 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc, | |||
| 82 | 82 | } | |
| 83 | 83 | Py_DECREF(v); | |
| 84 | 84 | } | |
| 85 | + Py_DECREF(n); | ||
| 85 | 86 | } | |
| 86 | 87 | if (doc != NULL) { | |
| 87 | 88 | v = PyString_FromString(doc); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments