#vulnerable code 
                                public static String exec(String cmd) throws IOException {
        Process process = Runtime.getRuntime().exec(cmd);
        InputStream inputStream = process.getInputStream();
        InputStream errorStream = process.getErrorStream();
        try {
            String err = IOUtils.toString(errorStream, "UTF-8");
            String out = IOUtils.toString(inputStream, "UTF-8");
            return err + "\n" + out;
        } finally {
            inputStream.close();
            errorStream.close();
        }
    } 
                            #location 4 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                             public static String exec(String cmd) throws IOException {
		
		CommandLine cmdLine = CommandLine.parse(cmd);
		DefaultExecutor executor = new DefaultExecutor();

		// 防止抛出异常
		executor.setExitValues(null);

		// 命令执行的超时时间
		ExecuteWatchdog watchdog = new ExecuteWatchdog(600000);
		executor.setWatchdog(watchdog);

		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
		executor.setStreamHandler(streamHandler);

		executor.execute(cmdLine);

		return outputStream.toString();
	}