Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db24dfba authored by Junyu Lai's avatar Junyu Lai Committed by Automerger Merge Worker
Browse files

Merge "Fix fd leak in KeepaliveTracker." into rvc-d1-dev am: c9f72532

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

Change-Id: I277aa6490272eb83eca87d01f0df1b6cf08f137e
parents d0cf46f6 c9f72532
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -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) {
        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) {
        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