summaryrefslogtreecommitdiffstats
path: root/Modules/_tracemalloc.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-24 10:28:20 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-24 10:28:20 (GMT)
commitd606ba7f5579a152d8826e10cdc528af2a5c0e10 (patch)
tree4e99a52152a69a01484f649507fe5335129b64e5 /Modules/_tracemalloc.c
parent7119b454fddcf0429b0ece4d18f747eb7ae6fe61 (diff)
downloadcpython-d606ba7f5579a152d8826e10cdc528af2a5c0e10.zip
cpython-d606ba7f5579a152d8826e10cdc528af2a5c0e10.tar.gz
cpython-d606ba7f5579a152d8826e10cdc528af2a5c0e10.tar.bz2
Issue #19741: fix tracemalloc_log_alloc(), handle _Py_HASHTABLE_SET() failure
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r--Modules/_tracemalloc.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 9dd4b19..5feb309 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();
}