Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 4a56e21

Browse files
authored
upsertMemory requires the lock. (#29)
Ensure that upsertMemory is called with the lock held from tryGetBackend.
1 parent 5ed1469 commit 4a56e21

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/store.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ tryGetBackend(struct LDStore *const store, const char *const kind,
875875
const char *const key, struct LDJSONRC **const result)
876876
{
877877
struct LDStoreCollectionItem collectionItem;
878+
bool status;
878879

879880
LD_ASSERT(store);
880881
LD_ASSERT(kind);
@@ -921,7 +922,11 @@ tryGetBackend(struct LDStore *const store, const char *const kind,
921922
}
922923

923924
if (LDi_isFeatureDeleted(deserialized)) {
924-
return upsertMemory(store, kind, deserialized);
925+
LDi_rwlock_wrlock(&store->cache->lock);
926+
status = upsertMemory(store, kind, deserialized);
927+
LDi_rwlock_wrunlock(&store->cache->lock);
928+
929+
return status;
925930
} else {
926931
if (!(deserializedRef = LDJSONRCNew(deserialized))) {
927932
LDJSONFree(deserialized);
@@ -937,10 +942,13 @@ tryGetBackend(struct LDStore *const store, const char *const kind,
937942

938943
*result = deserializedRef;
939944

940-
return upsertMemory(store, kind, dupe);
945+
LDi_rwlock_wrlock(&store->cache->lock);
946+
status = upsertMemory(store, kind, dupe);
947+
LDi_rwlock_wrunlock(&store->cache->lock);
948+
949+
return status;
941950
}
942951
} else {
943-
bool status;
944952
struct LDJSON *placeholder;
945953

946954
LD_ASSERT(store->cache);

0 commit comments

Comments
 (0)