#vulnerable code 
                                private void performTest(final String name) {
        final File target = new File(name);
        final Formatter fmt = new Formatter(System.out);

        double sumTime = 0;
        int n = 1;
        for (int i = 0; i < 10; i++) {
            try {
                ByteSourceFile byteSource = new ByteSourceFile(target);
                // This test code allows you to test cases where the
                // input is processed using Apache Imaging's
                // ByteSourceInputStream rather than the ByteSourceFile.
                // You might also want to experiment with ByteSourceArray.
                // FileInputStream fins = new FileInputStream(target);
                // BufferedInputStream bins = new BufferedInputStream(fins);
                // ByteSourceInputStream byteSource =
                // new ByteSourceInputStream(bins, target.getName());

                // ready the parser (you may modify this code block
                // to use your parser of choice)
                HashMap<String,Object> params = new HashMap<String,Object>();
                TiffImageParser tiffImageParser = new TiffImageParser();

                // load the file and record time needed to do so
                final long time0 = System.nanoTime();
                BufferedImage bImage = tiffImageParser.getBufferedImage(
                        byteSource, params);
                final long time1 = System.nanoTime();

                // tabulate results
                final double testTime = (time1 - time0) / 1000000.0;
                if (i > 1) {
                    n = i - 1;
                    sumTime += testTime;
                }
                final double avgTime = sumTime / n;

                // tabulate the memory results. Note that the
                // buffered image, the byte source, and the parser
                // are all still in scope. This approach is taken
                // to get some sense of peak memory use, but Java
                // may have already started collecting garbage,
                // so there are limits to the reliability of these
                // statistics
                final Runtime r = Runtime.getRuntime();
                final long freeMemory = r.freeMemory();
                final long totalMemory = r.totalMemory();
                final long usedMemory = totalMemory - freeMemory;

                if (i == 0) {
                    // print header info
                    fmt.format("\n");
                    fmt.format("Processing file: %s\n", target.getName());
                    fmt.format(" image size: %d by %d\n\n", bImage.getWidth(),
                            bImage.getHeight());
                    fmt.format(" time to load image    --         memory\n");
                    fmt.format(" time ms      avg ms   --    used mb   total mb\n");
                }
                fmt.format("%9.3f %9.3f    --  %9.3f %9.3f \n", testTime,
                        avgTime, usedMemory / (1024.0 * 1024.0), totalMemory
                                / (1024.0 * 1024.0));
                bImage = null;
                byteSource = null;
                params = null;
                tiffImageParser = null;
            } catch (final ImageReadException ire) {
                ire.printStackTrace();
                System.exit(-1);
            } catch (final IOException ioex) {
                ioex.printStackTrace();
                System.exit(-1);
            }

            try {
                // sleep between loop iterations allows time
                // for the JVM to clean up memory. The Netbeans IDE
                // doesn't "get" the fact that we're doing this operation
                // deliberately and is apt offer hints
                // suggesting that the code should be modified
                Runtime.getRuntime().gc();
                Thread.sleep(1000);
            } catch (final InterruptedException iex) {
                // this isn't fatal, but shouldn't happen
                iex.printStackTrace();
            }

        }
    } 
                            #location 35 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                private void performTest(final String name) {
        final File target = new File(name);
        final Formatter fmt = new Formatter(System.out);

        double sumTime = 0;
        int n = 1;
        for (int i = 0; i < 10; i++) {
            try {
                ByteSourceFile byteSource = new ByteSourceFile(target);
                // This test code allows you to test cases where the
                // input is processed using Apache Imaging's
                // ByteSourceInputStream rather than the ByteSourceFile.
                // You might also want to experiment with ByteSourceArray.
                // FileInputStream fins = new FileInputStream(target);
                // BufferedInputStream bins = new BufferedInputStream(fins);
                // ByteSourceInputStream byteSource =
                // new ByteSourceInputStream(bins, target.getName());

                // ready the parser (you may modify this code block
                // to use your parser of choice)
                HashMap<String,Object> params = new HashMap<String,Object>();
                TiffImageParser tiffImageParser = new TiffImageParser();

                // load the file and record time needed to do so
                final long time0 = System.nanoTime();
                BufferedImage bImage = tiffImageParser.getBufferedImage(
                        byteSource, params);
                final long time1 = System.nanoTime();

                // tabulate results
                final double testTime = (time1 - time0) / 1000000.0;
                if (i > 1) {
                    n = i - 1;
                    sumTime += testTime;
                }
                final double avgTime = sumTime / n;

                // tabulate the memory results. Note that the
                // buffered image, the byte source, and the parser
                // are all still in scope. This approach is taken
                // to get some sense of peak memory use, but Java
                // may have already started collecting garbage,
                // so there are limits to the reliability of these
                // statistics
                final Runtime r = Runtime.getRuntime();
                final long freeMemory = r.freeMemory();
                final long totalMemory = r.totalMemory();
                final long usedMemory = totalMemory - freeMemory;

                if (i == 0) {
                    // print header info
                    fmt.format("\n");
                    fmt.format("Processing file: %s\n", target.getName());
                    fmt.format(" image size: %d by %d\n\n", bImage.getWidth(),
                            bImage.getHeight());
                    fmt.format(" time to load image    --         memory\n");
                    fmt.format(" time ms      avg ms   --    used mb   total mb\n");
                }
                fmt.format("%9.3f %9.3f    --  %9.3f %9.3f \n", testTime,
                        avgTime, usedMemory / (1024.0 * 1024.0), totalMemory
                                / (1024.0 * 1024.0));
                bImage = null;
                byteSource = null;
                params = null;
                tiffImageParser = null;
            } catch (final ImageReadException ire) {
                ire.printStackTrace();
                System.exit(-1);
            } catch (final IOException ioex) {
                ioex.printStackTrace();
                System.exit(-1);
            } finally {
            	fmt.close();            	
            }

            try {
                // sleep between loop iterations allows time
                // for the JVM to clean up memory. The Netbeans IDE
                // doesn't "get" the fact that we're doing this operation
                // deliberately and is apt offer hints
                // suggesting that the code should be modified
                Runtime.getRuntime().gc();
                Thread.sleep(1000);
            } catch (final InterruptedException iex) {
                // this isn't fatal, but shouldn't happen
                iex.printStackTrace();
            }

        }
    }