summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2020-12-06 01:22:06 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-06 01:22:06 +0000
commitde25366cef03d23a274255982c938e11de1db9f5 (patch)
treeaf84e455f1c6fc444244e8d0daa30bd61279765b
parentba26e886a3dae360930c99ba0dbd2d375c995a31 (diff)
parent32b5003cf641ffcad9bb0d41d748906fd4b0dadf (diff)
downloadcore-de25366cef03d23a274255982c938e11de1db9f5.tar.gz
storaged: protect global proto_loaded am: 32b5003cf6
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/13113781 Change-Id: I45a2313d15210c0383916a03d875e50423cea0cd
-rw-r--r--storaged/include/storaged.h1
-rw-r--r--storaged/storaged.cpp6
2 files changed, 7 insertions, 0 deletions
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index 6f9204879..79b5d41ac 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -86,6 +86,7 @@ class storaged_t : public android::hardware::health::V2_0::IHealthInfoCallback,
sp<android::hardware::health::V2_0::IHealth> health;
unique_ptr<storage_info_t> storage_info;
static const uint32_t current_version;
+ Mutex proto_lock;
unordered_map<userid_t, bool> proto_loaded;
void load_proto(userid_t user_id);
char* prepare_proto(userid_t user_id, StoragedProto* proto);
diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp
index 573b8c563..b7aa89ff7 100644
--- a/storaged/storaged.cpp
+++ b/storaged/storaged.cpp
@@ -162,6 +162,8 @@ storaged_t::storaged_t(void) {
}
void storaged_t::add_user_ce(userid_t user_id) {
+ Mutex::Autolock _l(proto_lock);
+
if (!proto_loaded[user_id]) {
load_proto(user_id);
proto_loaded[user_id] = true;
@@ -169,6 +171,8 @@ void storaged_t::add_user_ce(userid_t user_id) {
}
void storaged_t::remove_user_ce(userid_t user_id) {
+ Mutex::Autolock _l(proto_lock);
+
proto_loaded[user_id] = false;
mUidm.clear_user_history(user_id);
RemoveFileIfExists(proto_path(user_id), nullptr);
@@ -298,6 +302,8 @@ void storaged_t::flush_proto(userid_t user_id, StoragedProto* proto) {
}
void storaged_t::flush_protos(unordered_map<int, StoragedProto>* protos) {
+ Mutex::Autolock _l(proto_lock);
+
for (auto& it : *protos) {
/*
* Don't flush proto if we haven't attempted to load it from file.