isc_refcount_increment0 is wrong, the code using it needs refactoring
isc_refcount_increment0() does two things and that's wrong.
The first purpose is to bump the value from
1making the object referenced.
The second purpose is to increment the reference counter.
This has several problems:
- You can't check whether the previous value really was
- When object becomes dereferenced with
isc_refcount_decrement() == 1, the
isc_refcount_increment0()can make it referenced again while destroying the object.
There are two things that we could do about it:
- Don't use isc_refcount API when it's not reference counting, prepare similar API for object counting (isc_objcount?)
isc_refcount_init()when initializing object for the first time (note that
isc_refcount_init()is not atomic)
- Always initialize the value to
1and adjust the code that destroys the object
Nevertheless, the overloading of the API for
<1, MAX> and
<0, MAX> reference counting is wrong.