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 S3BinaryCacheStoreImpl

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:17:59 +02:00
parent 17c94ca89e
commit f12f96bcbb

View file

@ -289,8 +289,6 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
, s3Helper(config->profile, config->region, config->scheme, config->endpoint) , s3Helper(config->profile, config->region, config->scheme, config->endpoint)
{ {
diskCache = getNarInfoDiskCache(); diskCache = getNarInfoDiskCache();
init();
} }
std::string getUri() override std::string getUri() override
@ -597,10 +595,12 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
ref<Store> S3BinaryCacheStoreImpl::Config::openStore() const ref<Store> S3BinaryCacheStoreImpl::Config::openStore() const
{ {
return make_ref<S3BinaryCacheStoreImpl>(ref{ auto store = make_ref<S3BinaryCacheStoreImpl>(ref{
// FIXME we shouldn't actually need a mutable config // FIXME we shouldn't actually need a mutable config
std::const_pointer_cast<S3BinaryCacheStore::Config>(shared_from_this()) std::const_pointer_cast<S3BinaryCacheStore::Config>(shared_from_this())
}); });
store->init();
return store;
} }
static RegisterStoreImplementation<S3BinaryCacheStoreImpl::Config> regS3BinaryCacheStore; static RegisterStoreImplementation<S3BinaryCacheStoreImpl::Config> regS3BinaryCacheStore;