Merge "Fix system_server crash while iterating CookieTagMap" am: dd5a31eb2d

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1990333

Change-Id: I04bd616a62ba77219c0ae812d2337e474b1fe2c2
This commit is contained in:
Maciej Żenczykowski
2022-02-19 22:03:23 +00:00
committed by Automerger Merge Worker

View File

@@ -1875,7 +1875,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private void deleteKernelTagData(int uid) { private void deleteKernelTagData(int uid) {
try { try {
mCookieTagMap.forEach((key, value) -> { mCookieTagMap.forEach((key, value) -> {
if (value.uid == uid) { // If SkDestroyListener deletes the socket tag while this code is running,
// forEach will either restart iteration from the beginning or return null,
// depending on when the deletion happens.
// If it returns null, continue iteration to delete the data and in fact it would
// just iterate from first key because BpfMap#getNextKey would return first key
// if the current key is not exist.
if (value != null && value.uid == uid) {
try { try {
mCookieTagMap.deleteEntry(key); mCookieTagMap.deleteEntry(key);
} catch (ErrnoException e) { } catch (ErrnoException e) {