#vulnerable code 
                                @Test
    public void testRepairDB() throws IOException {
        String directory = Paths.get("tmp", "DBRepairTest", "testRepairDB").toString();

        HaloDBOptions options = new HaloDBOptions();
        options.maxFileSize = 1024 * 1024;

        HaloDB db = getTestDB(directory, options);
        int noOfRecords = 5 * 1024 + 512;

        List<Record> records = TestUtils.insertRandomRecordsOfSize(db, noOfRecords, 1024-Record.Header.HEADER_SIZE);

        File latestDataFile = TestUtils.getLatestDataFile(directory);

        db.close();

        // trick the db to think that there was an unclean shutdown.
        DBMetaData dbMetaData = new DBMetaData(directory);
        dbMetaData.setOpen(true);
        dbMetaData.storeToFile();

        db = getTestDBWithoutDeletingFiles(directory, options);

        // latest file should have been repaired and deleted. 
        Assert.assertFalse(latestDataFile.exists());

        Assert.assertEquals(db.size(), noOfRecords);
        for (Record r : records) {
            Assert.assertEquals(db.get(r.getKey()), r.getValue());
        }
    } 
                            #location 22 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testRepairDB() throws IOException {
        String directory = Paths.get("tmp", "DBRepairTest", "testRepairDB").toString();

        HaloDBOptions options = new HaloDBOptions();
        options.maxFileSize = 1024 * 1024;

        HaloDB db = getTestDB(directory, options);
        int noOfRecords = 5 * 1024 + 512; // 5 files with 1024 records and 1 with 512 records. 

        List<Record> records = TestUtils.insertRandomRecordsOfSize(db, noOfRecords, 1024-Record.Header.HEADER_SIZE);

        File latestDataFile = TestUtils.getLatestDataFile(directory);

        db.close();

        // trick the db to think that there was an unclean shutdown.
        DBMetaData dbMetaData = new DBMetaData(directory);
        dbMetaData.setOpen(true);
        dbMetaData.storeToFile();

        db = getTestDBWithoutDeletingFiles(directory, options);

        // latest file should have been repaired and deleted. 
        Assert.assertFalse(latestDataFile.exists());

        Assert.assertEquals(db.size(), noOfRecords);
        for (Record r : records) {
            Assert.assertEquals(db.get(r.getKey()), r.getValue());
        }
    }