summaryrefslogtreecommitdiffstats
path: root/Modules/_tracemalloc.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-24 11:27:59 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-24 11:27:59 (GMT)
commit08facd200975d8001bf045bab407adf727e6fc9f (patch)
tree03e02dcc885082e42681fd880ef332df797e3de1 /Modules/_tracemalloc.c
parentfc91285c93ea1e1c152b73fd0a5a703bf564d596 (diff)
downloadcpython-08facd200975d8001bf045bab407adf727e6fc9f.zip
cpython-08facd200975d8001bf045bab407adf727e6fc9f.tar.gz
cpython-08facd200975d8001bf045bab407adf727e6fc9f.tar.bz2
Issue #19741: cleanup tracemalloc_realloc()
Explain that unhandled error case is very unlikely
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r--Modules/_tracemalloc.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 22ec5dd..1a782f6 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -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);
if (ptr2 != NULL) {
- if (ptr != NULL)
+ if (ptr != NULL) {
+ /* resize */
tracemalloc_log_free(ptr);
- if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
- if (ptr == NULL) {
+ if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
+ /* 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 */
alloc->free(alloc->ctx, ptr2);
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);