Skip to content

Commit c631856

Browse files
committed
Fix test_weakref.test_threaded_weak_key_dict_copy refleak
1 parent 51c6625 commit c631856

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Objects/object.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ _Py_DecRefSharedDebug(PyObject *o, const char *filename, int lineno)
345345
&shared, new_shared));
346346

347347
if (should_queue) {
348+
#ifdef Py_REF_DEBUG
349+
_Py_IncRefTotal(_PyInterpreterState_GET());
350+
#endif
348351
_Py_brc_queue_object(o);
349352
}
350353
else if (new_shared == _Py_REF_MERGED) {
@@ -395,13 +398,13 @@ _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra)
395398
Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
396399
do {
397400
refcnt = Py_ARITHMETIC_RIGHT_SHIFT(Py_ssize_t, shared, _Py_REF_SHARED_SHIFT);
398-
if (_Py_REF_IS_MERGED(shared)) {
399-
return refcnt;
400-
}
401-
402401
refcnt += (Py_ssize_t)op->ob_ref_local;
403402
refcnt += extra;
404403

404+
#ifdef Py_REF_DEBUG
405+
_Py_AddRefTotal(_PyInterpreterState_GET(), extra);
406+
#endif
407+
405408
new_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
406409
} while (!_Py_atomic_compare_exchange_ssize(&op->ob_ref_shared,
407410
&shared, new_shared));

Objects/obmalloc.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,12 @@ get_mimalloc_allocated_blocks(PyInterpreterState *interp)
10731073
mi_heap_visit_blocks(heap, false, &count_blocks, &allocated_blocks);
10741074
}
10751075
}
1076-
// TODO(sgross): count blocks in abandoned segments.
1076+
1077+
mi_abandoned_pool_t *pool = &interp->mimalloc.abandoned_pool;
1078+
for (uint8_t tag = 0; tag < _Py_MIMALLOC_HEAP_COUNT; tag++) {
1079+
_mi_abandoned_pool_visit_blocks(pool, tag, false, &count_blocks,
1080+
&allocated_blocks);
1081+
}
10771082
#else
10781083
// TODO(sgross): this only counts the current thread's blocks.
10791084
mi_heap_t *heap = mi_heap_get_default();

0 commit comments

Comments
 (0)