#vulnerable code 
                                void mergeTombstoneFiles() throws IOException {
        if (!options.isCleanUpTombstonesDuringOpen()) {
            logger.info("CleanUpTombstonesDuringOpen is not enabled, returning");
            return;
        }

        File[] tombStoneFiles = dbDirectory.listTombstoneFiles();

        logger.info("About to merge {} tombstone files ...", tombStoneFiles.length);
        TombstoneFile mergedTombstoneFile = null;

        // Use compaction job rate as write rate limiter to avoid IO impact
        final RateLimiter rateLimiter = RateLimiter.create(options.getCompactionJobRate());

        for (File file : tombStoneFiles) {
            TombstoneFile tombstoneFile = new TombstoneFile(file, options, dbDirectory);
            if (currentTombstoneFile != null && tombstoneFile.getName().equals(currentTombstoneFile.getName())) {
                continue; // not touch current tombstone file
            }

            tombstoneFile.open();
            TombstoneFile.TombstoneFileIterator iterator = tombstoneFile.newIterator();

            long count = 0;
            while (iterator.hasNext()) {
                TombstoneEntry entry = iterator.next();
                rateLimiter.acquire(entry.size());
                count++;
                mergedTombstoneFile = rollOverTombstoneFile(entry, mergedTombstoneFile);
                mergedTombstoneFile.write(entry);
            }
            if (count > 0) {
                logger.debug("Merged {} tombstones from {} to {}",
                    count, tombstoneFile.getName(), mergedTombstoneFile.getName());
            }
            tombstoneFile.close();
            tombstoneFile.delete();
        }

        logger.info("Tombstone files count, before merge:{}, after merge:{}",
            tombStoneFiles.length, dbDirectory.listTombstoneFiles().length);
    } 
                            #location 17 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                void close() throws IOException {
        writeLock.lock();
        try {
            if (isClosing) {
                // instance already closed.
                return;
            }
            isClosing = true;

            try {
                if(!compactionManager.stopCompactionThread(true))
                    setIOErrorFlag();
            } catch (IOException e) {
                logger.error("Error while stopping compaction thread. Setting IOError flag", e);
                setIOErrorFlag();
            }

            if (options.isCleanUpInMemoryIndexOnClose())
                inMemoryIndex.close();

            if (currentWriteFile != null) {
                currentWriteFile.flushToDisk();
                currentWriteFile.getIndexFile().flushToDisk();
                currentWriteFile.close();
            }
            if (currentTombstoneFile != null) {
                currentTombstoneFile.flushToDisk();
                currentTombstoneFile.close();
            }

            for (HaloDBFile file : readFileMap.values()) {
                file.close();
            }

            DBMetaData metaData = new DBMetaData(dbDirectory);
            metaData.loadFromFileIfExists();
            metaData.setOpen(false);
            metaData.storeToFile();

            dbDirectory.close();

            if (dbLock != null) {
                dbLock.close();
            }
        } finally {
            writeLock.unlock();
        }
    }