#fixed code
                                public static void main(final String... args) throws Throwable {

        toInfinityAndBeyond();

        final Options opts = new Options();

        opts.addOption(
                builder("n")
                        .longOpt("basename")
                        .hasArg().argName("BASENAME")
                        .desc("The base name of the simulator instance")
                        .build());

        opts.addOption(
                builder()
                        .longOpt("name-factory")
                        .hasArg().argName("FACTORY")
                        .desc("The name factory to use")
                        .build());

        opts.addOption(
                builder("c")
                        .longOpt("count")
                        .hasArg().argName("COUNT")
                        .type(Integer.class)
                        .desc("The number of instances to start")
                        .build());

        opts.addOption(
                builder("a")
                        .longOpt("account-name")
                        .hasArg().argName("NAME")
                        .desc("The name of the account (defaults to 'kapua-sys')")
                        .build());

        opts.addOption(
                builder("s")
                        .longOpt("seconds")
                        .hasArg().argName("SECONDS")
                        .type(Long.class)
                        .desc("Shutdown simulator after <SECONDS> seconds")
                        .build());

        opts.addOption("?", "help", false, null);

        {
            final OptionGroup broker = new OptionGroup();
            broker.setRequired(false);

            broker.addOption(
                    builder("h")
                            .longOpt("broker-host")
                            .hasArg().argName("HOST")
                            .desc("Only the hostname of the broker, used for building the full URL")
                            .build());
            broker.addOption(
                    builder("b")
                            .longOpt("broker")
                            .hasArg().argName("URL")
                            .desc("The full URL to the broker").build());

            opts.addOptionGroup(broker);
        }

        {
            final OptionGroup logging = new OptionGroup();
            logging.setRequired(false);

            logging.addOption(builder("q").longOpt("quiet").desc("Suppress output").build());
            logging.addOption(builder("v").longOpt("verbose").desc("Show more output").build());
            logging.addOption(builder("d").longOpt("debug").desc("Show debug output").build());

            opts.addOptionGroup(logging);
        }

        final CommandLine cli;
        try {
            cli = new DefaultParser().parse(opts, args);
        } catch (final ParseException e) {
            System.err.println(e.getLocalizedMessage());
            System.exit(-1);
            return;
        }

        if (cli.hasOption('?')) {
            showHelp(opts);
            System.exit(0);
        }

        setupLogging(cli);

        final String basename = replace(cli.getOptionValue('n', env("KSIM_BASE_NAME", "sim-")));
        final String nameFactoryName = cli.getOptionValue("name-factory", env("KSIM_NAME_FACTORY", null));
        final int count = Integer.parseInt(replace(cli.getOptionValue('c', env("KSIM_NUM_GATEWAYS", "1"))));
        final String brokerHost = replace(cli.getOptionValue("bh"));
        final String broker = replace(cli.getOptionValue('b', createBrokerUrl(Optional.ofNullable(brokerHost))));
        final String accountName = replace(cli.getOptionValue('a', env("KSIM_ACCOUNT_NAME", "kapua-sys")));
        final long shutdownAfter = Long
                .parseLong(replace(cli.getOptionValue('s', Long.toString(Long.MAX_VALUE / 1_000L))));

        dumpEnv();

        logger.info("Starting simulation ...");
        logger.info("\tbasename : {}", basename);
        logger.info("\tname-factory : {}", nameFactoryName);
        logger.info("\tcount: {}", count);
        logger.info("\tbroker: {}", broker);
        logger.info("\taccount-name: {}", accountName);

        final ScheduledExecutorService downloadExecutor = Executors
                .newSingleThreadScheduledExecutor(new NameThreadFactory("DownloadSimulator"));

        final List<AutoCloseable> close = new LinkedList<>();

        final NameFactory nameFactory = createNameFactory(nameFactoryName)
                .orElseGet(() -> NameFactories.prefixed(basename));

        try {
            for (int i = 1; i <= count; i++) {

                final String name = nameFactory.generateName(i);
                logger.info("Creating instance #{} - {}", i, name);

                final GatewayConfiguration configuration = new GatewayConfiguration(broker, accountName, name);

                final Set<Application> apps = new HashSet<>();
                apps.add(new SimpleCommandApplication(s -> String.format("Command '%s' not found", s)));
                apps.add(AnnotatedApplication.build(new SimpleDeployApplication(downloadExecutor)));

                final MqttAsyncTransport transport = new MqttAsyncTransport(configuration);
                close.add(transport);
                final Simulator simulator = new Simulator(configuration, transport, apps);
                close.add(simulator);
            }

            Thread.sleep(shutdownAfter * 1_000L);
            logger.info("Bye bye...");
        } finally {
            downloadExecutor.shutdown();
            closeAll(close);
        }

        logger.info("Exiting...");
    }
#vulnerable code 
                                public static void main(final String... args) throws Throwable {

        toInfinityAndBeyond();

        final Options opts = new Options();
        opts.addOption("n", "basename", true, "The base name of the simulator instance");
        opts.addOption(null, "name-factory", true, "The name factory to use");
        opts.addOption("c", "count", true, "The number of instances to start");
        opts.addOption("h", "broker-host", true, "The broker's host");
        opts.addOption("b", "broker", true, "The URL to the broker");
        opts.addOption("a", "account-name", true, "The name of the account");
        opts.addOption("s", "shutdown", true, "Shutdown simulator after x seconds");

        final CommandLine cli = new DefaultParser().parse(opts, args);

        final String basename = replace(cli.getOptionValue('n', env("KSIM_BASE_NAME", "sim-")));
        final String nameFactoryName = cli.getOptionValue("name-factory", env("KSIM_NAME_FACTORY", null));
        final int count = Integer.parseInt(replace(cli.getOptionValue('c', env("KSIM_NUM_GATEWAYS", "1"))));
        final String brokerHost = replace(cli.getOptionValue("bh"));
        final String broker = replace(cli.getOptionValue('b', createBrokerUrl(Optional.ofNullable(brokerHost))));
        final String accountName = replace(cli.getOptionValue('a', env("KSIM_ACCOUNT_NAME", "kapua-sys")));
        final long shutdownAfter = Long
                .parseLong(replace(cli.getOptionValue('s', Long.toString(Long.MAX_VALUE / 1_000L))));

        dumpEnv();

        logger.info("Starting simulation ...");
        logger.info("\tbasename : {}", basename);
        logger.info("\tname-factory : {}", nameFactoryName);
        logger.info("\tcount: {}", count);
        logger.info("\tbroker: {}", broker);
        logger.info("\taccount-name: {}", accountName);

        final ScheduledExecutorService downloadExecutor = Executors
                .newSingleThreadScheduledExecutor(new NameThreadFactory("DownloadSimulator"));

        final List<AutoCloseable> close = new LinkedList<>();

        final NameFactory nameFactory = createNameFactory(nameFactoryName)
                .orElseGet(() -> NameFactories.prefixed(basename));

        try {
            for (int i = 1; i <= count; i++) {

                final String name = nameFactory.generateName(i);
                logger.info("Creating instance #{} - {}", i, name);

                final GatewayConfiguration configuration = new GatewayConfiguration(broker, accountName, name);

                final Set<Application> apps = new HashSet<>();
                apps.add(new SimpleCommandApplication(s -> String.format("Command '%s' not found", s)));
                apps.add(AnnotatedApplication.build(new SimpleDeployApplication(downloadExecutor)));

                final MqttAsyncTransport transport = new MqttAsyncTransport(configuration);
                close.add(transport);
                final Simulator simulator = new Simulator(configuration, transport, apps);
                close.add(simulator);
            }

            Thread.sleep(shutdownAfter * 1_000L);
            logger.info("Bye bye...");
        } finally {
            downloadExecutor.shutdown();
            closeAll(close);
        }

        logger.info("Exiting...");
    } 
                            #location 52 
                            #vulnerability type RESOURCE_LEAK