mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Issue #19741: cleanup tracemalloc_realloc()
Explain that unhandled error case is very unlikely
This commit is contained in:
parent
fc91285c93
commit
08facd2009
1 changed files with 15 additions and 8 deletions
|
@ -563,20 +563,27 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size, int gil_held)
|
||||||
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
|
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
|
||||||
|
|
||||||
if (ptr2 != NULL) {
|
if (ptr2 != NULL) {
|
||||||
if (ptr != NULL)
|
if (ptr != NULL) {
|
||||||
|
/* resize */
|
||||||
tracemalloc_log_free(ptr);
|
tracemalloc_log_free(ptr);
|
||||||
|
|
||||||
if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
|
if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
|
||||||
if (ptr == NULL) {
|
/* Memory allocation failed. The error cannot be reported to
|
||||||
|
the caller, because realloc() may already have shrinked the
|
||||||
|
memory block and so removed bytes.
|
||||||
|
|
||||||
|
This case is very unlikely since we just released an hash
|
||||||
|
entry, so we have enough free bytes to allocate the new
|
||||||
|
entry. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* new allocation */
|
||||||
|
if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
|
||||||
/* Memory allocation failed */
|
/* Memory allocation failed */
|
||||||
alloc->free(alloc->ctx, ptr2);
|
alloc->free(alloc->ctx, ptr2);
|
||||||
ptr2 = NULL;
|
ptr2 = NULL;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
/* Memory allocation failed. The error cannot be reported to
|
|
||||||
the caller, because realloc() may already have shrinked the
|
|
||||||
memory block and so removed bytes. */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_reentrant(0);
|
set_reentrant(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue