[Python-checkins] cpython: Issue #19741: fix tracemalloc_log_alloc(), handle _Py_HASHTABLE_SET() failure
victor.stinner
python-checkins at python.org
Sun Nov 24 11:29:11 CET 2013
http://hg.python.org/cpython/rev/c189ea6b586b
changeset: 87492:c189ea6b586b
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Nov 24 11:28:20 2013 +0100
summary:
Issue #19741: fix tracemalloc_log_alloc(), handle _Py_HASHTABLE_SET() failure
files:
Modules/_tracemalloc.c | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -447,19 +447,28 @@
#endif
traceback = traceback_new();
- if (traceback == NULL)
+ if (traceback == NULL) {
+ /* Memory allocation failed. The error cannot be reported to the
+ caller, because realloc() may already have shrink the memory block
+ and so removed bytes. */
return;
+ }
trace.size = size;
trace.traceback = traceback;
TABLES_LOCK();
- assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
- tracemalloc_traced_memory += size;
- if (tracemalloc_traced_memory > tracemalloc_max_traced_memory)
- tracemalloc_max_traced_memory = tracemalloc_traced_memory;
-
- _Py_HASHTABLE_SET(tracemalloc_traces, ptr, trace);
+ if (_Py_HASHTABLE_SET(tracemalloc_traces, ptr, trace) == 0) {
+ assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
+ tracemalloc_traced_memory += size;
+ if (tracemalloc_traced_memory > tracemalloc_max_traced_memory)
+ tracemalloc_max_traced_memory = tracemalloc_traced_memory;
+ }
+ else {
+ /* Hashtabled failed to add a new entry because of a memory allocation
+ failure. Same than above, the error cannot be reported to the
+ caller. */
+ }
TABLES_UNLOCK();
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list