#vulnerable code 
                                @Test
    public void testOneAtATime() throws IOException {
        ChronicleConfig config = ChronicleConfig.TEST.clone();
        config.indexBlockSize(128); // very small
        config.dataBlockSize(128);  // very small
        final String basePath = TMP + "/testOneAtATime";
        ChronicleTools.deleteOnExit(basePath);

        File indexFile = new File(basePath + ".index");

        for (int i = 0; i < 100; i++) {
            if (i % 10 == 0)
                System.out.println("i: " + i);

            long indexFileSize = indexFile.length();
            IndexedChronicle chronicle = new IndexedChronicle(basePath);
            assertEquals("Index should not grow on open (i=" + i + ")", indexFileSize, indexFile.length());

            if (i == 0) {
                ExcerptTailer tailer = chronicle.createTailer();
                assertFalse(tailer.nextIndex());
                Excerpt excerpt = chronicle.createExcerpt();
                assertFalse(excerpt.index(0));
            }

            ExcerptAppender appender = chronicle.createAppender();
            appender.startExcerpt();
            appender.writeDouble(i);
            appender.finish();
//            ChronicleIndexReader.main(basePath+".index");

            ExcerptTailer tailer = chronicle.createTailer();
            long[] indexes = new long[i + 1];
            long lastIndex = -1;
            for (int j = 0; j <= i; j++) {
                assertTrue(tailer.nextIndex());
                assertTrue(tailer.index() + " > " + lastIndex, tailer.index() > lastIndex);
                lastIndex = tailer.index();
                double d = tailer.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, tailer.remaining());
                indexes[j] = tailer.index();
                tailer.finish();
            }
            assertFalse(tailer.nextIndex());
            Excerpt excerpt = chronicle.createExcerpt();
            // forward
            for (int j = 0; j < i; j++) {
                assertTrue(excerpt.index(indexes[j]));
                double d = excerpt.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, excerpt.remaining());
                excerpt.finish();
            }
            assertFalse(excerpt.index(indexes[indexes.length - 1] + 1));
            // backward
            for (int j = i - 1; j >= 0; j--) {
                assertTrue(excerpt.index(indexes[j]));
                double d = excerpt.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, excerpt.remaining());
                excerpt.finish();
            }
            assertFalse(excerpt.index(-1));
            chronicle.close();
        }
    } 
                            #location 24 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testOneAtATime() throws IOException {
        ChronicleConfig config = ChronicleConfig.TEST.clone();
        config.indexBlockSize(128); // very small
        config.dataBlockSize(128);  // very small
        final String basePath = TMP + "/testOneAtATime";
        ChronicleTools.deleteOnExit(basePath);

        File indexFile = new File(basePath + ".index");

        for (int i = 0; i < 1000; i++) {
            if (i % 10 == 0)
                System.out.println("i: " + i);

            long indexFileSize = indexFile.length();
            IndexedChronicle chronicle = new IndexedChronicle(basePath, config);
            assertEquals("Index should not grow on open (i=" + i + ")", indexFileSize, indexFile.length());

            if (i == 0) {
                ExcerptTailer tailer = chronicle.createTailer();
                assertFalse(tailer.nextIndex());
                Excerpt excerpt = chronicle.createExcerpt();
                assertFalse(excerpt.index(0));
            }

            ExcerptAppender appender = chronicle.createAppender();
            appender.startExcerpt();
            appender.writeDouble(i);
            appender.finish();
//            ChronicleIndexReader.main(basePath+".index");

            ExcerptTailer tailer = chronicle.createTailer();
            long[] indexes = new long[i + 1];
            long lastIndex = -1;
            for (int j = 0; j <= i; j++) {
                assertTrue(tailer.nextIndex());
                assertTrue(tailer.index() + " > " + lastIndex, tailer.index() > lastIndex);
                lastIndex = tailer.index();
                double d = tailer.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, tailer.remaining());
                indexes[j] = tailer.index();
                tailer.finish();
            }
            assertFalse(tailer.nextIndex());
            Excerpt excerpt = chronicle.createExcerpt();
            // forward
            for (int j = 0; j < i; j++) {
                assertTrue(excerpt.index(indexes[j]));
                double d = excerpt.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, excerpt.remaining());
                excerpt.finish();
            }
            assertFalse(excerpt.index(indexes[indexes.length - 1] + 1));
            // backward
            for (int j = i - 1; j >= 0; j--) {
                assertTrue(excerpt.index(indexes[j]));
                double d = excerpt.readDouble();
                assertEquals(j, d, 0.0);
                assertEquals(0, excerpt.remaining());
                excerpt.finish();
            }
            assertFalse(excerpt.index(-1));
            chronicle.close();
        }
    }