#fixed code
                                private void listenForEventPackets() throws IOException {
        latch.countDown();
        ByteArrayInputStream inputStream = channel.getInputStream();
        try {
            while (true) {
                try {
                    inputStream.peek();
                } catch (SocketException e) {
                    if (!connected) {
                        break;
                    }
                    throw e;
                }
                int packetLength = inputStream.readInteger(3);
                inputStream.skip(1); // 1 byte for sequence
                int marker = inputStream.read();
                byte[] bytes = inputStream.read(packetLength - 1);
                if (marker == 0xFF) {
                    ErrorPacket errorPacket = new ErrorPacket(bytes);
                    throw new IOException(errorPacket.getErrorCode() + " - " + errorPacket.getErrorMessage());
                }
                Event event = eventDeserializer.nextEvent(new ByteArrayInputStream(bytes));
                notifyEventListeners(event);
            }
        } finally {
            disconnect();
        }
    }
#vulnerable code 
                                private void listenForEventPackets() throws IOException {
        latch.countDown();
        ByteArrayInputStream inputStream = channel.getInputStream();
        while (channel.isOpen()) {
            int packetLength = inputStream.readInteger(3);
            inputStream.skip(2); // 1 byte for sequence and 1 for marker
            ByteArrayInputStream eventByteArray = new ByteArrayInputStream(inputStream.read(packetLength - 1));
            Event event = eventDeserializer.nextEvent(eventByteArray);
            notifyEventListeners(event);
        }
    } 
                            #location 8 
                            #vulnerability type RESOURCE_LEAK