Skip to content

Commit 5a6ef73

Browse files
author
Dianne Hackborn
committed
Fix issue #5595933: GREF leak due to race condition in...
...LoadedApk.ServiceDispatcher.connected , LoadedApk.forgetServiceDispatcher Don't be stupid if we receive a new binding to a ServiceConnection after it has already been unbound. Change-Id: I85a49de97372bf9af55542a89031f0b7a2ac8fbb
1 parent 15843aa commit 5a6ef73

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/java/android/app/LoadedApk.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ static final class ServiceDispatcher {
901901
private RuntimeException mUnbindLocation;
902902

903903
private boolean mDied;
904+
private boolean mForgotten;
904905

905906
private static class ConnectionInfo {
906907
IBinder binder;
@@ -959,6 +960,7 @@ void doForget() {
959960
ci.binder.unlinkToDeath(ci.deathMonitor, 0);
960961
}
961962
mActiveConnections.clear();
963+
mForgotten = true;
962964
}
963965
}
964966

@@ -1020,6 +1022,11 @@ public void doConnected(ComponentName name, IBinder service) {
10201022
ServiceDispatcher.ConnectionInfo info;
10211023

10221024
synchronized (this) {
1025+
if (mForgotten) {
1026+
// We unbound before receiving the connection; ignore
1027+
// any connection received.
1028+
return;
1029+
}
10231030
old = mActiveConnections.get(name);
10241031
if (old != null && old.binder == service) {
10251032
// Huh, already have this one. Oh well!

0 commit comments

Comments
 (0)