apple / apple/foundationdb

Replace flow reference counter with memory safe implementation

Open
#4,035 1 comment 1 reaction 1 assignee Claimed by @sears View on GitHub
Dominant language
C++
Stars
16.7k
Forks
1.6k
Avg merge
1d 20h
Merged PRs (30d)
126

Description

Flow’s reference counted types come into being as a raw pointer with a reference count of 1. Wrapping them in additional references does not increase the reference count. Instead, callers are expected to manage the references by invoking addRef manually. Failure to do so leads to use after free errors.

Modern C++ reference counted types maintain the invariant that, in the absence of pointer arithmetic or manual calls to delete, all live Reference objects point to a valid object. We should establish this invariant by modifying or replacing the Flow ReferenceCounted type.

Also, Flow includes a compile time option (which is disabled) to make its ReferenceCounted objects threadsafe. It also includes a ThreadSafeReferenceCounted type. The latter is used in a few places in the code base. It is generally difficult to write (or understand) thread safe code that relies on racing access and deallocation of objects. As part of cleaning this up, we should examine (and perhaps rewrite) those call sites.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.