Re: [TECH TOPIC] Rust for Linux

Wedson Almeida Filho
2021-07-08T13:42:01Z

On Thu, Jul 08, 2021 at 09:20:25AM +0200, Geert Uytterhoeven wrote:
> > Weak references need to upgraded to strong references before the underlying
> > objects can be accessed; upgrading may fail if the strong count has gone to
> > zero. It is, naturally, implemented as an increment that avoids going from 0 to
> > 1. It is safe to try to do it because the memory is kept alive while there are
> > weak references.
>
> What does "may fail" imply?

Upgrading is essentially calling `refcount_inc_not_zero` on the strong count.
It succeeds when the count is already non-zero, it fails when the count is zero.

So "may fail" here means "your attempt to upgrade came too late, the object is
gone". (The memory is still around so that attempts to upgrade don't cause UAF,
but the object is gone.)