Skip to content

Commit

Permalink
Ensure locking when mocking.
Browse files Browse the repository at this point in the history
Summary:
Leaky Singleton's mocking function obtains the entry from the vault and proceeds
to modify it without locking the entry, which may race with any future use of
the singleton or the creation function.

Reviewed By: yfeldblum

Differential Revision: D34254633

fbshipit-source-id: c59db898b71b25d3026b903a0bfa40e3dbf9306f
  • Loading branch information
Stan Swidwinski authored and facebook-github-bot committed Feb 23, 2022
1 parent 0d94bc7 commit a315c6b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions folly/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ class LeakySingleton {
}

auto& entry = entryInstance();
std::lock_guard<std::mutex> lg(entry.mutex);
if (entry.ptr) {
annotate_object_leaked(std::exchange(entry.ptr, nullptr));
}
Expand Down

0 comments on commit a315c6b

Please sign in to comment.