Skip to content

Commit 44963da

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

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct LocalBinaryCacheStore :
3939
, BinaryCacheStore{*config}
4040
, config{config}
4141
{
42-
init();
4342
}
4443

4544
void init() override;
@@ -126,10 +125,12 @@ StringSet LocalBinaryCacheStoreConfig::uriSchemes()
126125
}
127126

128127
ref<Store> LocalBinaryCacheStoreConfig::openStore() const {
129-
return make_ref<LocalBinaryCacheStore>(ref{
128+
auto store = make_ref<LocalBinaryCacheStore>(ref{
130129
// FIXME we shouldn't actually need a mutable config
131130
std::const_pointer_cast<LocalBinaryCacheStore::Config>(shared_from_this())
132131
});
132+
store->init();
133+
return store;
133134
}
134135

135136
static RegisterStoreImplementation<LocalBinaryCacheStore::Config> regLocalBinaryCacheStore;

0 commit comments

Comments
 (0)