#vulnerable code 
                                @Test
    public void testOverTCP() throws IOException, InterruptedException {
        final String basePathSource = getIndexedTestPath("-source");
        final String basePathSink = getIndexedTestPath("-sink");

        // NOTE: the sink and source must have different chronicle files.
        // TODO, make more robust.
        final int messages = 5 * 1000 * 1000;

        final Chronicle source = new ChronicleSource(ChronicleQueueBuilder.indexed(basePathSource).build(), PORT + 1);
        final Chronicle sink = new ChronicleSink(ChronicleQueueBuilder.indexed(basePathSink).build(), "localhost", PORT + 1);

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ExcerptAppender excerpt = source.createAppender();
                    for (int i = 1; i <= messages; i++) {
                        // use a size which will cause mis-alignment.
                        excerpt.startExcerpt();
                        excerpt.writeLong(i);
                        excerpt.append(' ');
                        excerpt.append(i);
                        excerpt.append('\n');
                        excerpt.finish();
                    }
                    System.out.println(System.currentTimeMillis() + ": Finished writing messages");
                } catch (Exception e) {
                    throw new AssertionError(e);
                }
            }
        });

        long start = System.nanoTime();
        t.start();
        ExcerptTailer excerpt = sink.createTailer();
        int count = 0;
        for (int i = 1; i <= messages; i++) {
            while (!excerpt.nextIndex()) {
                count++;
            }

            long n = excerpt.readLong();
            String text = excerpt.parseUTF(StopCharTesters.CONTROL_STOP);
            if (i != n) {
                assertEquals('\'' + text + '\'', i, n);
            }

            excerpt.finish();
        }

        sink.close();
        System.out.println("There were " + count + " InSynk messages");
        t.join();

        source.close();
        long time = System.nanoTime() - start;
        System.out.printf("Messages per second %,d%n", (int) (messages * 1e9 / time));

        assertIndexedClean(basePathSource);
        assertIndexedClean(basePathSink);
    } 
                            #location 26 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testOverTCP() throws IOException, InterruptedException {
        final String basePathSource = getIndexedTestPath("-source");
        final String basePathSink = getIndexedTestPath("-sink");

        // NOTE: the sink and source must have different chronicle files.
        // TODO, make more robust.
        final int messages = 5 * 1000 * 1000;

        final Chronicle source = ChronicleQueueBuilder.indexed(basePathSource)
            .source()
                .bindAddress(BASE_PORT + 1)
            .build();
        final Chronicle sink = ChronicleQueueBuilder.indexed(basePathSink)
            .sink()
                .connectAddress("localhost", BASE_PORT + 1)
            .build();

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ExcerptAppender excerpt = source.createAppender();
                    for (int i = 1; i <= messages; i++) {
                        // use a size which will cause mis-alignment.
                        excerpt.startExcerpt();
                        excerpt.writeLong(i);
                        excerpt.append(' ');
                        excerpt.append(i);
                        excerpt.append('\n');
                        excerpt.finish();
                    }
                    System.out.println(System.currentTimeMillis() + ": Finished writing messages");
                } catch (Exception e) {
                    throw new AssertionError(e);
                }
            }
        });

        long start = System.nanoTime();
        t.start();
        ExcerptTailer excerpt = sink.createTailer();
        int count = 0;
        for (int i = 1; i <= messages; i++) {
            while (!excerpt.nextIndex()) {
                count++;
            }

            long n = excerpt.readLong();
            String text = excerpt.parseUTF(StopCharTesters.CONTROL_STOP);
            if (i != n) {
                assertEquals('\'' + text + '\'', i, n);
            }

            excerpt.finish();
        }

        sink.close();
        System.out.println("There were " + count + " InSynk messages");
        t.join();

        source.close();
        long time = System.nanoTime() - start;
        System.out.printf("Messages per second %,d%n", (int) (messages * 1e9 / time));

        assertIndexedClean(basePathSource);
        assertIndexedClean(basePathSink);
    }