#vulnerable code 
                                public Boolean checkConnection() {
        Socket socket = new Socket();
        InetSocketAddress address = new InetSocketAddress(host, port);
        InputStreamReader input = null;
        try {
            socket.setSoTimeout(10);
            socket.connect(address, 50);

            input = new InputStreamReader(
                    socket.getInputStream());

            String ret = "< hi >";

            for(int i=0;i<6;i++) {
                if(input.read() != ret.charAt(i)) {
                    logger.log(Level.INFO, "Could not connect to host");
                    return false;
                }
            }
        } catch (IOException ex) {
            logger.log(Level.INFO, "Could not connect to host", ex);
            return false;
        }
        finally {
            if(input != null) {
                    try {
                    input.close();
                } catch (IOException ex) {
                    Logger.getLogger(BusURL.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        return true;
    } 
                            #location 10 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                public Boolean checkConnection() {
        Socket socket = new Socket();
        InetSocketAddress address = new InetSocketAddress(host, port);
        InputStreamReader input = null;
        OutputStreamWriter output = null;
        try {
            socket.setSoTimeout(10);
            socket.connect(address, 50);

            input = new InputStreamReader(
                    socket.getInputStream());

            output = new OutputStreamWriter(socket.getOutputStream());

            String ret = "< hi >";

            for(int i=0;i<6;i++) {
                if(input.read() != ret.charAt(i)) {
                    logger.log(Level.INFO, "Could not connect to host");
                    return false;
                }
            }

            output.write("< open " + bus + " >");
            output.flush();

            ret = "< ok >";
            for(int i=0;i<6;i++) {
                if(input.read() != ret.charAt(i)) {
                    logger.log(Level.INFO, "Could not open bus");
                    return false;
                }
            }

        } catch (IOException ex) {
            logger.log(Level.INFO, "Could not connect to host", ex);
            return false;
        }
        finally {
            if(input != null) {
                    try {
                    input.close();
                    output.close();
                } catch (IOException ex) {
                    logger.log(Level.SEVERE, null, ex);
                }
            }
        }

        return true;
    }