[Tizen] Fix memory leak when ReadFile failed 09/317409/1 tizen_6.0
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 04:05:40 +0000 (13:05 +0900)
Change-Id: Ia5e78159176170ae594ae702c42a8d5a4b4acb67
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/adaptor-framework/generic/file-loader-impl-generic.cpp

index b6d211e..e4fd2f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
@@ -49,8 +49,8 @@ int ReadFile(const std::string& filename, Dali::Vector<uint8_t>& memblock, Dali:
 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;
+  int            errorCode = 0;
+  std::ifstream* file{nullptr};
 
   if( fileType == Dali::FileLoader::BINARY )
   {
@@ -75,8 +75,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
@@ -84,6 +82,8 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     DALI_LOG_ERROR( "file open failed for: \"%s\"\n", filename.c_str() );
   }
 
+  delete file;
+
   return errorCode;
 }