Skip to content

Commit 5d58eb0

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Fix a few memory leaks in the input dispatcher. (DO NOT MERGE)" into ics-mr1
2 parents 820b45c + 9f63f12 commit 5d58eb0

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

services/input/InputDispatcher.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,10 +1914,21 @@ void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,
19141914
connection->getInputChannelName());
19151915
logOutboundMotionDetailsLocked(" ", splitMotionEntry);
19161916
#endif
1917-
eventEntry = splitMotionEntry;
1917+
enqueueDispatchEntriesLocked(currentTime, connection,
1918+
splitMotionEntry, inputTarget, resumeWithAppendedMotionSample);
1919+
splitMotionEntry->release();
1920+
return;
19181921
}
19191922
}
19201923

1924+
// Not splitting. Enqueue dispatch entries for the event as is.
1925+
enqueueDispatchEntriesLocked(currentTime, connection, eventEntry, inputTarget,
1926+
resumeWithAppendedMotionSample);
1927+
}
1928+
1929+
void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
1930+
const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
1931+
bool resumeWithAppendedMotionSample) {
19211932
// Resume the dispatch cycle with a freshly appended motion sample.
19221933
// First we check that the last dispatch entry in the outbound queue is for the same
19231934
// motion event to which we appended the motion sample. If we find such a dispatch
@@ -2054,9 +2065,6 @@ void InputDispatcher::enqueueDispatchEntryLocked(
20542065
DispatchEntry* dispatchEntry = new DispatchEntry(eventEntry, // increments ref
20552066
inputTargetFlags, inputTarget->xOffset, inputTarget->yOffset,
20562067
inputTarget->scaleFactor);
2057-
if (dispatchEntry->hasForegroundTarget()) {
2058-
incrementPendingForegroundDispatchesLocked(eventEntry);
2059-
}
20602068

20612069
// Handle the case where we could not stream a new motion sample because the consumer has
20622070
// already consumed the motion event (otherwise the corresponding dispatch entry would
@@ -2085,6 +2093,7 @@ void InputDispatcher::enqueueDispatchEntryLocked(
20852093
LOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent key event",
20862094
connection->getInputChannelName());
20872095
#endif
2096+
delete dispatchEntry;
20882097
return; // skip the inconsistent event
20892098
}
20902099
break;
@@ -2126,12 +2135,18 @@ void InputDispatcher::enqueueDispatchEntryLocked(
21262135
LOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent motion event",
21272136
connection->getInputChannelName());
21282137
#endif
2138+
delete dispatchEntry;
21292139
return; // skip the inconsistent event
21302140
}
21312141
break;
21322142
}
21332143
}
21342144

2145+
// Remember that we are waiting for this dispatch to complete.
2146+
if (dispatchEntry->hasForegroundTarget()) {
2147+
incrementPendingForegroundDispatchesLocked(eventEntry);
2148+
}
2149+
21352150
// Enqueue the dispatch entry.
21362151
connection->outboundQueue.enqueueAtTail(dispatchEntry);
21372152
}
@@ -2470,14 +2485,17 @@ void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
24702485

24712486
void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
24722487
const sp<Connection>& connection, const CancelationOptions& options) {
2488+
if (connection->status == Connection::STATUS_BROKEN) {
2489+
return;
2490+
}
2491+
24732492
nsecs_t currentTime = now();
24742493

24752494
mTempCancelationEvents.clear();
24762495
connection->inputState.synthesizeCancelationEvents(currentTime,
24772496
mTempCancelationEvents, options);
24782497

2479-
if (! mTempCancelationEvents.isEmpty()
2480-
&& connection->status != Connection::STATUS_BROKEN) {
2498+
if (!mTempCancelationEvents.isEmpty()) {
24812499
#if DEBUG_OUTBOUND_EVENT_DETAILS
24822500
LOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
24832501
"with reality: %s, mode=%d.",

services/input/InputDispatcher.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,9 @@ class InputDispatcher : public InputDispatcherInterface {
10701070
void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
10711071
EventEntry* eventEntry, const InputTarget* inputTarget,
10721072
bool resumeWithAppendedMotionSample);
1073+
void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
1074+
EventEntry* eventEntry, const InputTarget* inputTarget,
1075+
bool resumeWithAppendedMotionSample);
10731076
void enqueueDispatchEntryLocked(const sp<Connection>& connection,
10741077
EventEntry* eventEntry, const InputTarget* inputTarget,
10751078
bool resumeWithAppendedMotionSample, int32_t dispatchMode);

0 commit comments

Comments
 (0)