Skip to content

Commit c0cb3dc

Browse files
author
Jeff Brown
committed
Fix a few memory leaks in the input dispatcher.
Bug: 5862398 Change-Id: Iae3284a223b8307f541a7987f90f5b28e70b9244
1 parent dc89357 commit c0cb3dc

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
@@ -1906,10 +1906,21 @@ void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,
19061906
connection->getInputChannelName());
19071907
logOutboundMotionDetailsLocked(" ", splitMotionEntry);
19081908
#endif
1909-
eventEntry = splitMotionEntry;
1909+
enqueueDispatchEntriesLocked(currentTime, connection,
1910+
splitMotionEntry, inputTarget, resumeWithAppendedMotionSample);
1911+
splitMotionEntry->release();
1912+
return;
19101913
}
19111914
}
19121915

1916+
// Not splitting. Enqueue dispatch entries for the event as is.
1917+
enqueueDispatchEntriesLocked(currentTime, connection, eventEntry, inputTarget,
1918+
resumeWithAppendedMotionSample);
1919+
}
1920+
1921+
void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
1922+
const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
1923+
bool resumeWithAppendedMotionSample) {
19131924
// Resume the dispatch cycle with a freshly appended motion sample.
19141925
// First we check that the last dispatch entry in the outbound queue is for the same
19151926
// motion event to which we appended the motion sample. If we find such a dispatch
@@ -2046,9 +2057,6 @@ void InputDispatcher::enqueueDispatchEntryLocked(
20462057
DispatchEntry* dispatchEntry = new DispatchEntry(eventEntry, // increments ref
20472058
inputTargetFlags, inputTarget->xOffset, inputTarget->yOffset,
20482059
inputTarget->scaleFactor);
2049-
if (dispatchEntry->hasForegroundTarget()) {
2050-
incrementPendingForegroundDispatchesLocked(eventEntry);
2051-
}
20522060

20532061
// Handle the case where we could not stream a new motion sample because the consumer has
20542062
// already consumed the motion event (otherwise the corresponding dispatch entry would
@@ -2077,6 +2085,7 @@ void InputDispatcher::enqueueDispatchEntryLocked(
20772085
ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent key event",
20782086
connection->getInputChannelName());
20792087
#endif
2088+
delete dispatchEntry;
20802089
return; // skip the inconsistent event
20812090
}
20822091
break;
@@ -2118,12 +2127,18 @@ void InputDispatcher::enqueueDispatchEntryLocked(
21182127
ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent motion event",
21192128
connection->getInputChannelName());
21202129
#endif
2130+
delete dispatchEntry;
21212131
return; // skip the inconsistent event
21222132
}
21232133
break;
21242134
}
21252135
}
21262136

2137+
// Remember that we are waiting for this dispatch to complete.
2138+
if (dispatchEntry->hasForegroundTarget()) {
2139+
incrementPendingForegroundDispatchesLocked(eventEntry);
2140+
}
2141+
21272142
// Enqueue the dispatch entry.
21282143
connection->outboundQueue.enqueueAtTail(dispatchEntry);
21292144
}
@@ -2462,14 +2477,17 @@ void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
24622477

24632478
void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
24642479
const sp<Connection>& connection, const CancelationOptions& options) {
2480+
if (connection->status == Connection::STATUS_BROKEN) {
2481+
return;
2482+
}
2483+
24652484
nsecs_t currentTime = now();
24662485

24672486
mTempCancelationEvents.clear();
24682487
connection->inputState.synthesizeCancelationEvents(currentTime,
24692488
mTempCancelationEvents, options);
24702489

2471-
if (! mTempCancelationEvents.isEmpty()
2472-
&& connection->status != Connection::STATUS_BROKEN) {
2490+
if (!mTempCancelationEvents.isEmpty()) {
24732491
#if DEBUG_OUTBOUND_EVENT_DETAILS
24742492
ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
24752493
"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)