Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17ffb458 authored by Steven Moreland's avatar Steven Moreland
Browse files

RefBase: better hints for debugging

Recommendation to enable best-practice compiler flags when seeing errors
that show memory is not handled correctly. Oftentimes, implicit
assignment of refcounts on these objects is the cause of these failures.

Bug: 393013610
Test: N/A
Change-Id: I6c6ef13a0ac11884e02d608dedc7bb6892c3a583
parent 364d5dfb
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -492,7 +492,10 @@ void RefBase::decStrong(const void* id) const
#if PRINT_REFS
    ALOGD("decStrong of %p from %p: cnt=%d\n", this, id, c);
#endif
    LOG_ALWAYS_FATAL_IF(BAD_STRONG(c), "decStrong() called on %p too many times",
    LOG_ALWAYS_FATAL_IF(
            BAD_STRONG(c),
            "decStrong() called on %p too many times, possible memory corruption. Consider "
            "compiling with ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION for better errors",
            refs);
    if (c == 1) {
        std::atomic_thread_fence(std::memory_order_acquire);
@@ -576,7 +579,10 @@ void RefBase::weakref_type::decWeak(const void* id)
    weakref_impl* const impl = static_cast<weakref_impl*>(this);
    impl->removeWeakRef(id);
    const int32_t c = impl->mWeak.fetch_sub(1, std::memory_order_release);
    LOG_ALWAYS_FATAL_IF(BAD_WEAK(c), "decWeak called on %p too many times",
    LOG_ALWAYS_FATAL_IF(
            BAD_WEAK(c),
            "decWeak called on %p too many times, possible memory corruption. Consider compiling "
            "with ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION for better errors",
            this);
    if (c != 1) return;
    atomic_thread_fence(std::memory_order_acquire);