[Tizen] Fix memory leak when ReadFile failed 07/317407/1 accepted/tizen/8.0/unified/20240924.162411
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 10 Sep 2024 03:56:20 +0000 (12:56 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 10 Sep 2024 03:59:37 +0000 (12:59 +0900)
Change-Id: Ia5e78159176170ae594ae702c42a8d5a4b4acb67
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/adaptor-framework/generic/file-loader-impl-generic.cpp

index ebd71f4a19c137a16bc1c3becb613c1372474d18..0d7fc67ae45872aa011dc9430d187b857a679494 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ template<typename T>
 int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector<T>& memblock, Dali::FileLoader::FileType fileType)
 {
   int            errorCode = 0;
-  std::ifstream* file;
+  std::ifstream* file{nullptr};
 
   if(fileType == Dali::FileLoader::BINARY)
   {
@@ -72,8 +72,6 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     file->read(reinterpret_cast<char*>(memblock.Begin()), fileSize);
     file->close();
 
-    delete file;
-
     errorCode = 1;
   }
   else
@@ -82,6 +80,8 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     DALI_LOG_ERROR("file open failed for: \"%s\", error : %s\n", filename.c_str(), strerror_r(errno, buf, 512));
   }
 
+  delete file;
+
   return errorCode;
 }