diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-11-24 11:28:20 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-11-24 11:28:20 +0100 |
commit | 33db06238d98997217419046f51566e11f299270 (patch) | |
tree | 0e2bf34f06bccc87b2b04a20057a9a5973959c72 /Modules | |
parent | 59f7a4fec65b46cb5e169bf212ab0462a6989b59 (diff) | |
download | cpython-33db06238d98997217419046f51566e11f299270.tar.gz |
Issue #19741: fix tracemalloc_log_alloc(), handle _Py_HASHTABLE_SET() failure
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_tracemalloc.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 9dd4b19bcc..5feb3099d5 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -447,19 +447,28 @@ tracemalloc_log_alloc(void *ptr, size_t size) #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(); } |