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

Commit 725e8f68 authored by Erik Kline's avatar Erik Kline
Browse files

Always close file descriptors

Every error thrown leaked a netlink NETFILTER socket.

Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes
    - enabled tethering and tried to cause conntrack updates to sessions
      that had expired (which causes ErrnoExceptions to be thrown)
      while monitoring lsof for system_server's NETFILTER sockets

Bug: 32163131
Bug: 64976634
Bug: 110122306

Change-Id: Ib52b812e8434c27ad9f2596666400c13e03c2216
parent d004710e
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -59,10 +59,9 @@ public class NetlinkSocket {
        final String errPrefix = "Error in NetlinkSocket.sendOneShotKernelMessage";
        final long IO_TIMEOUT = 300L;

        FileDescriptor fd;
        final FileDescriptor fd = forProto(nlProto);

        try {
            fd = forProto(nlProto);
            connectToKernel(fd);
            sendMessage(fd, msg, 0, msg.length, IO_TIMEOUT);
            final ByteBuffer bytes = recvMessage(fd, DEFAULT_RECV_BUFSIZE, IO_TIMEOUT);
@@ -96,10 +95,10 @@ public class NetlinkSocket {
        } catch (SocketException e) {
            Log.e(TAG, errPrefix, e);
            throw new ErrnoException(errPrefix, EIO, e);
        }

        } finally {
            IoUtils.closeQuietly(fd);
        }
    }

    public static FileDescriptor forProto(int nlProto) throws ErrnoException {
        final FileDescriptor fd = Os.socket(AF_NETLINK, SOCK_DGRAM, nlProto);