Skip to content

Commit f12f96b

Browse files
committed
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.
1 parent 17c94ca commit f12f96b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libstore/s3-binary-cache-store.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
289289
, s3Helper(config->profile, config->region, config->scheme, config->endpoint)
290290
{
291291
diskCache = getNarInfoDiskCache();
292-
293-
init();
294292
}
295293

296294
std::string getUri() override
@@ -597,10 +595,12 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
597595

598596
ref<Store> S3BinaryCacheStoreImpl::Config::openStore() const
599597
{
600-
return make_ref<S3BinaryCacheStoreImpl>(ref{
598+
auto store = make_ref<S3BinaryCacheStoreImpl>(ref{
601599
// FIXME we shouldn't actually need a mutable config
602600
std::const_pointer_cast<S3BinaryCacheStore::Config>(shared_from_this())
603601
});
602+
store->init();
603+
return store;
604604
}
605605

606606
static RegisterStoreImplementation<S3BinaryCacheStoreImpl::Config> regS3BinaryCacheStore;

0 commit comments

Comments
 (0)