File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -447,19 +447,28 @@ tracemalloc_log_alloc(void *ptr, size_t size)
447447#endif
448448
449449 traceback = traceback_new ();
450- if (traceback == NULL )
450+ if (traceback == NULL ) {
451+ /* Memory allocation failed. The error cannot be reported to the
452+ caller, because realloc() may already have shrink the memory block
453+ and so removed bytes. */
451454 return ;
455+ }
452456
453457 trace .size = size ;
454458 trace .traceback = traceback ;
455459
456460 TABLES_LOCK ();
457- assert (tracemalloc_traced_memory <= PY_SIZE_MAX - size );
458- tracemalloc_traced_memory += size ;
459- if (tracemalloc_traced_memory > tracemalloc_max_traced_memory )
460- tracemalloc_max_traced_memory = tracemalloc_traced_memory ;
461-
462- _Py_HASHTABLE_SET (tracemalloc_traces , ptr , trace );
461+ if (_Py_HASHTABLE_SET (tracemalloc_traces , ptr , trace ) == 0 ) {
462+ assert (tracemalloc_traced_memory <= PY_SIZE_MAX - size );
463+ tracemalloc_traced_memory += size ;
464+ if (tracemalloc_traced_memory > tracemalloc_max_traced_memory )
465+ tracemalloc_max_traced_memory = tracemalloc_traced_memory ;
466+ }
467+ else {
468+ /* Hashtabled failed to add a new entry because of a memory allocation
469+ failure. Same than above, the error cannot be reported to the
470+ caller. */
471+ }
463472 TABLES_UNLOCK ();
464473}
465474
You can’t perform that action at this time.
0 commit comments