diff --git a/coding/coding_tests/file_data_test.cpp b/coding/coding_tests/file_data_test.cpp
index 3a4684ad34..d402f5354b 100644
--- a/coding/coding_tests/file_data_test.cpp
+++ b/coding/coding_tests/file_data_test.cpp
@@ -30,7 +30,7 @@ namespace file_data_test
 #ifdef OMIM_OS_WINDOWS
   void CheckFileOK(std::string const & name)
   {
-    base::FileData f(name, base::FileData::OP_READ);
+    base::FileData f(name, base::FileData::Op::READ);
 
     uint64_t const size = f.Size();
     TEST_EQUAL ( size, name.size(), () );
@@ -69,7 +69,7 @@ UNIT_TEST(FileData_NoDiskSpace)
 
   try
   {
-    base::FileData f(name, base::FileData::OP_WRITE_TRUNCATE);
+    base::FileData f(name, base::FileData::Op::WRITE_TRUNCATE);
 
     for (size_t i = 0; i < 100; ++i)
       f.Write(&bytes[0], bytes.size());
@@ -91,7 +91,7 @@ UNIT_TEST(FileData_SharingAV_Windows)
     MakeFile(name1);
 
     // lock file, will check sharing access
-    base::FileData f1(name1, base::FileData::OP_READ);
+    base::FileData f1(name1, base::FileData::Op::READ);
 
     // try rename or delete locked file
     TEST(!base::RenameFileX(name1, name2), ());
diff --git a/coding/internal/file_data.cpp b/coding/internal/file_data.cpp
index d0e3e3b3a9..2d47ee1b54 100644
--- a/coding/internal/file_data.cpp
+++ b/coding/internal/file_data.cpp
@@ -50,7 +50,7 @@ FileData::FileData(string const & fileName, Op op)
   {
 #if defined(_MSC_VER)
     // Move file pointer to the end of the file to make it consistent with other platforms
-    if (op == Op::OP_APPEND)
+    if (op == Op::APPEND)
       fseek64(m_File, 0, SEEK_END);
 #endif
     return;
diff --git a/editor/editor_tests/config_loader_test.cpp b/editor/editor_tests/config_loader_test.cpp
index a6a6a39082..0c427d21c2 100644
--- a/editor/editor_tests/config_loader_test.cpp
+++ b/editor/editor_tests/config_loader_test.cpp
@@ -48,7 +48,7 @@ UNIT_TEST(ConfigLoader_Base)
 
 UNIT_TEST(ConfigLoader_SaveLoadHash)
 {
-  ScopedFile sf("test.hash", ScopedFile::Mode::Create);
+  ScopedFile sf("test.hash", ScopedFile::Mode::DoNotCreate);
   auto const testHash = "12345 678909 87654 321 \n 32";
 
   ConfigLoader::SaveHash(testHash, sf.GetFullPath());
diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp
index 52fc003d1e..3a22748220 100644
--- a/editor/editor_tests/osm_editor_test.cpp
+++ b/editor/editor_tests/osm_editor_test.cpp
@@ -216,6 +216,7 @@ EditorTest::~EditorTest()
 {
   editor::tests_support::TearDownEditorForTesting();
 
+  m_dataSource.ClearCache();
   for (auto const & file : m_mwmFiles)
     Cleanup(file);
 }
@@ -1036,6 +1037,7 @@ void EditorTest::LoadMapEditsTest()
   sort(features.begin(), features.end());
   TEST_EQUAL(features, loadedFeatures, ());
 
+  m_dataSource.DeregisterMap(m_mwmFiles.back().GetCountryFile());
   TEST(RemoveMwm(rfMwmId), ());
 
   auto const newRfMwmId = BuildMwm("RF", [](TestMwmBuilder & builder)
diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp
index b41fd7540c..44f96c8e32 100644
--- a/generator/feature_sorter.cpp
+++ b/generator/feature_sorter.cpp
@@ -114,11 +114,12 @@ public:
     }
 
     // File Writer finalization function with adding section to the main mwm file.
-    auto const finalizeFn = [this](std::unique_ptr<TmpFile> && w, std::string const & tag)
+    auto const finalizeFn = [this](std::unique_ptr<TmpFile> && tmpFile, std::string const & tag)
     {
-      w->Flush();
+      auto & w = tmpFile->GetWriter();
+      w.Flush();
       FilesContainerW writer(m_filename, FileWriter::OP_WRITE_EXISTING);
-      writer.Write(w->GetName(), tag);
+      writer.Write(w.GetName(), tag);
     };
 
     for (size_t i = 0; i < m_header.GetScalesCount(); ++i)
@@ -145,8 +146,8 @@ public:
 
   void operator()(FeatureBuilder & fb)
   {
-    GeometryHolder holder([this](int i) -> FileWriter & { return *m_geoFile[i]; },
-                          [this](int i) -> FileWriter & { return *m_trgFile[i]; }, fb, m_header);
+    GeometryHolder holder([this](int i) -> FileWriter & { return m_geoFile[i]->GetWriter(); },
+                          [this](int i) -> FileWriter & { return m_trgFile[i]->GetWriter(); }, fb, m_header);
 
     if (!fb.IsPoint())
     {
@@ -310,11 +311,21 @@ private:
   using Points = std::vector<m2::PointD>;
   using Polygons = std::list<Points>;
 
-  class TmpFile : public FileWriter
+  class TmpFile
   {
+    std::unique_ptr<FileWriter> m_writer;
   public:
-    explicit TmpFile(std::string const & filePath) : FileWriter(filePath) {}
-    ~TmpFile() override { DeleteFileX(GetName()); }
+    explicit TmpFile(std::string const & filePath)
+      : m_writer(std::make_unique<FileWriter>(filePath)) {}
+
+    FileWriter & GetWriter() { return *m_writer; }
+
+    ~TmpFile()
+    {
+      auto const name = m_writer->GetName();
+      m_writer.reset();
+      FileWriter::DeleteFileX(name);
+    }
   };
 
   using TmpFiles = std::vector<std::unique_ptr<TmpFile>>;
diff --git a/generator/generator_tests_support/test_with_custom_mwms.cpp b/generator/generator_tests_support/test_with_custom_mwms.cpp
index c3f1491433..85b044e7a5 100644
--- a/generator/generator_tests_support/test_with_custom_mwms.cpp
+++ b/generator/generator_tests_support/test_with_custom_mwms.cpp
@@ -20,6 +20,7 @@ TestWithCustomMwms::TestWithCustomMwms()
 
 TestWithCustomMwms::~TestWithCustomMwms()
 {
+  m_dataSource.ClearCache();
   for (auto const & file : m_files)
     Cleanup(file);
 }
diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp
index 266f5e62d6..f1c6e79978 100644
--- a/platform/platform_tests/platform_test.cpp
+++ b/platform/platform_tests/platform_test.cpp
@@ -276,8 +276,10 @@ UNIT_TEST(MkDirRecursively)
 
   CHECK(resetDir(workPath), ());
   auto const filePath = base::JoinPath(workPath, "test1");
-  FileWriter testFile(filePath);
   SCOPE_GUARD(removeTestFile, bind(&base::DeleteFileX, filePath));
+  {
+    FileWriter testFile(filePath);
+  }
 
   TEST(!Platform::MkDirRecursively(path), ());
   TEST(!Platform::IsFileExistsByFullPath(path), ());
diff --git a/search/highlighting.hpp b/search/highlighting.hpp
index 380dc9f551..1d7f93320e 100644
--- a/search/highlighting.hpp
+++ b/search/highlighting.hpp
@@ -15,7 +15,7 @@ namespace search
 {
 template <typename LowTokensIter, typename F>
 void SearchStringTokensIntersectionRanges(std::string const & s, LowTokensIter itLowBeg,
-                                          LowTokensIter itLowEnd, F f)
+                                          LowTokensIter itLowEnd, F && f)
 {
   // split input query by tokens and prefix
   search::Delimiters delimsTest;
diff --git a/track_analyzing/track_analyzing_tests/track_archive_reader_tests.cpp b/track_analyzing/track_analyzing_tests/track_archive_reader_tests.cpp
index 273f92476f..e29915c7fb 100644
--- a/track_analyzing/track_analyzing_tests/track_archive_reader_tests.cpp
+++ b/track_analyzing/track_analyzing_tests/track_archive_reader_tests.cpp
@@ -93,8 +93,8 @@ UNIT_TEST(UnpackTrackArchiveDataTest)
     FileReader containerReader(containerFileName);
     buffer.resize(containerReader.Size());
     containerReader.Read(0 /* file begin */, buffer.data(), buffer.size());
-    FileWriter::DeleteFileX(containerFileName);
   }
+  FileWriter::DeleteFileX(containerFileName);
 
   // Step 2.4: Wrap as multipart data
   stringstream multipartStream;
diff --git a/transit/world_feed/world_feed_tests/world_feed_tests.cpp b/transit/world_feed/world_feed_tests/world_feed_tests.cpp
index f8ec994c1f..256e2023ee 100644
--- a/transit/world_feed/world_feed_tests/world_feed_tests.cpp
+++ b/transit/world_feed/world_feed_tests/world_feed_tests.cpp
@@ -233,7 +233,7 @@ UNIT_TEST(Transit_GTFS_ProjectStopToLine_Simple)
 
   // Test point_C projection in backward direction.
   TEST_EQUAL(ResT(5, false),
-               PrepareNearestPointOnTrack(point_C, std::nullopt, shape.size() /* prevIndex */,
+               PrepareNearestPointOnTrack(point_C, std::nullopt, shape.size() - 1 /* prevIndex */,
                                           Direction::Backward, shape), ());
 
   // Test point_B projection in backward direction.
@@ -384,7 +384,7 @@ UNIT_TEST(Transit_GTFS_ProjectStopToLine_NearCircle)
   shape = initialShape;
   reverse(shape.begin(), shape.end());
   TEST_EQUAL(ResT(17, true),
-               PrepareNearestPointOnTrack(point_A, std::nullopt, shape.size() /* prevIndex */,
+               PrepareNearestPointOnTrack(point_A, std::nullopt, shape.size() - 1/* prevIndex */,
                                           Direction::Backward, shape), ());
   TEST(base::AlmostEqualAbs(coordA, shape[17], kEps), (coordA, shape[17]));