1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

Fix virtual method calls during construction in LocalBinaryCacheStore

Move init() call from constructor to openStore() method to avoid calling
virtual methods during object construction. This prevents undefined
behavior when virtual methods are called before the object is fully
constructed.
This commit is contained in:
Jörg Thalheim 2025-07-17 11:15:51 +02:00
parent f12f96bcbb
commit 44963da787

View file

@ -39,7 +39,6 @@ struct LocalBinaryCacheStore :
, BinaryCacheStore{*config}
, config{config}
{
init();
}
void init() override;
@ -126,10 +125,12 @@ StringSet LocalBinaryCacheStoreConfig::uriSchemes()
}
ref<Store> LocalBinaryCacheStoreConfig::openStore() const {
return make_ref<LocalBinaryCacheStore>(ref{
auto store = make_ref<LocalBinaryCacheStore>(ref{
// FIXME we shouldn't actually need a mutable config
std::const_pointer_cast<LocalBinaryCacheStore::Config>(shared_from_this())
});
store->init();
return store;
}
static RegisterStoreImplementation<LocalBinaryCacheStore::Config> regLocalBinaryCacheStore;