#vulnerable code 
                                @Test
    public void testConnection() throws InvalidMessageException, IOException {
        PeerConnection connection = new PeerConnection(mock(Peer.class), clientChannel);

        Message message;

        server.writeMessage(new Handshake(new byte[20], new byte[20]));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.HANDSHAKE, message.getType());

        server.writeMessage(new Bitfield(new byte[2 << 9]));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.BITFIELD, message.getType());
        assertEquals(2 << 9, ((Bitfield) message).getBitfield().length);

        server.writeMessage(new Request(1, 2, 3));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.REQUEST, message.getType());
        assertEquals(1, ((Request) message).getPieceIndex());
        assertEquals(2, ((Request) message).getOffset());
        assertEquals(3, ((Request) message).getLength());
    } 
                            #location 25 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testConnection() throws InvalidMessageException, IOException {
        IPeerConnection connection = new PeerConnection(mock(Peer.class), clientChannel);

        Message message;

        server.writeMessage(new Handshake(new byte[20], new byte[20]));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.HANDSHAKE, message.getType());

        server.writeMessage(new Bitfield(new byte[2 << 9]));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.BITFIELD, message.getType());
        assertEquals(2 << 9, ((Bitfield) message).getBitfield().length);

        server.writeMessage(new Request(1, 2, 3));
        message = connection.readMessageNow();
        assertNotNull(message);
        assertEquals(MessageType.REQUEST, message.getType());
        assertEquals(1, ((Request) message).getPieceIndex());
        assertEquals(2, ((Request) message).getOffset());
        assertEquals(3, ((Request) message).getLength());
    }