Issue #19741: fix tracemalloc_log_alloc(), handle _Py_HASHTABLE_SET() failure

This commit is contained in:
Victor Stinner 2013-11-24 11:28:20 +01:00
parent 7119b454fd
commit d606ba7f55
1 changed files with 16 additions and 7 deletions

View File

@ -447,19 +447,28 @@ tracemalloc_log_alloc(void *ptr, size_t size)
#endif #endif
traceback = traceback_new(); 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; return;
}
trace.size = size; trace.size = size;
trace.traceback = traceback; trace.traceback = traceback;
TABLES_LOCK(); TABLES_LOCK();
assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size); if (_Py_HASHTABLE_SET(tracemalloc_traces, ptr, trace) == 0) {
tracemalloc_traced_memory += size; assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
if (tracemalloc_traced_memory > tracemalloc_max_traced_memory) tracemalloc_traced_memory += size;
tracemalloc_max_traced_memory = tracemalloc_traced_memory; if (tracemalloc_traced_memory > tracemalloc_max_traced_memory)
tracemalloc_max_traced_memory = tracemalloc_traced_memory;
_Py_HASHTABLE_SET(tracemalloc_traces, ptr, trace); }
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(); TABLES_UNLOCK();
} }