Code RoomResource reference use-after-free
MediumPrep Room Coding #2041

Resource reference use-after-free

Code reviewConcurrencyMid–Senior~25 min

Review this C++ reference-counted handle. `release()` is called from multiple threads when handles go out of scope.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1struct Resource {
2 std::atomic<int> refs{1};
3 Data* data;
4 
5 void acquire() { refs.fetch_add(1, std::memory_order_relaxed); }
6 
7 void release() {
8 if (refs.fetch_sub(1, std::memory_order_relaxed) == 1) {
9 delete data;
10 data = nullptr;
11 }
12 }
13};
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.