Fix fd leak in KeepaliveTracker.
The semantics of FileDescriptor in AIDL are that the callee must close
the file descriptor it receives manually.
Fix: 157789860
Bug: 155136951
Test: treehugger
Change-Id: Ice9fc9abe2959a84ad138a95c900dff676653665
Merged-In: Ice9fc9abe2959a84ad138a95c900dff676653665
(cherry picked from commit db8ae41da2)
This commit is contained in:
committed by
Junyu Lai
parent
62c3a4f46b
commit
e5a64d49da
@@ -220,6 +220,8 @@ import com.android.server.utils.PriorityDump;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
@@ -7519,18 +7521,34 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
public void startNattKeepaliveWithFd(Network network, FileDescriptor fd, int resourceId,
|
||||
int intervalSeconds, ISocketKeepaliveCallback cb, String srcAddr,
|
||||
String dstAddr) {
|
||||
mKeepaliveTracker.startNattKeepalive(
|
||||
getNetworkAgentInfoForNetwork(network), fd, resourceId,
|
||||
intervalSeconds, cb,
|
||||
srcAddr, dstAddr, NattSocketKeepalive.NATT_PORT);
|
||||
try {
|
||||
mKeepaliveTracker.startNattKeepalive(
|
||||
getNetworkAgentInfoForNetwork(network), fd, resourceId,
|
||||
intervalSeconds, cb,
|
||||
srcAddr, dstAddr, NattSocketKeepalive.NATT_PORT);
|
||||
} finally {
|
||||
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
||||
// startNattKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
||||
if (fd != null && Binder.getCallingPid() != Process.myPid()) {
|
||||
IoUtils.closeQuietly(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTcpKeepalive(Network network, FileDescriptor fd, int intervalSeconds,
|
||||
ISocketKeepaliveCallback cb) {
|
||||
enforceKeepalivePermission();
|
||||
mKeepaliveTracker.startTcpKeepalive(
|
||||
getNetworkAgentInfoForNetwork(network), fd, intervalSeconds, cb);
|
||||
try {
|
||||
enforceKeepalivePermission();
|
||||
mKeepaliveTracker.startTcpKeepalive(
|
||||
getNetworkAgentInfoForNetwork(network), fd, intervalSeconds, cb);
|
||||
} finally {
|
||||
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
||||
// startTcpKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
||||
if (fd != null && Binder.getCallingPid() != Process.myPid()) {
|
||||
IoUtils.closeQuietly(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user