Open kpu opened 1 year ago
The reference counter is a bare size_t https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L15-L16 and the pointer type is a bare pointer: https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L137
size_t
If two threads destroy their references simultaneously, then both enter this function: https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L23-L28 It's possible both threads will read x != 0 and x->references_ == 2 then commit 1 back and leak the object.
x != 0
x->references_ == 2
Aside: this line doesn't do anything since it's in a function that takes type* x https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L26
type* x
The reference counter is a bare
size_t
https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L15-L16 and the pointer type is a bare pointer: https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L137If two threads destroy their references simultaneously, then both enter this function: https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L23-L28 It's possible both threads will read
x != 0
andx->references_ == 2
then commit 1 back and leak the object.Aside: this line doesn't do anything since it's in a function that takes
type* x
https://github.com/marian-nmt/marian-dev/blob/3daf4ee2906583dfc86e4f6986b40f843e7e3a3c/src/common/intrusive_ptr.h#L26