瀏覽代碼

Fix file handle leak in ZipArchive and FileAccessZip

Mateo "Kuruk" Miccino 5 月之前
父節點
當前提交
38c69f1814
共有 2 個文件被更改,包括 2 次插入6 次删除
  1. 2 5
      core/io/file_access_zip.cpp
  2. 0 1
      core/io/file_access_zip.h

+ 2 - 5
core/io/file_access_zip.cpp

@@ -174,7 +174,6 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint6
 
 	Package pkg;
 	pkg.filename = p_path;
-	pkg.zfile = zfile;
 	packages.push_back(pkg);
 	int pkg_num = packages.size() - 1;
 
@@ -201,6 +200,8 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint6
 		}
 	}
 
+	unzClose(zfile);
+
 	return true;
 }
 
@@ -225,10 +226,6 @@ ZipArchive::ZipArchive() {
 }
 
 ZipArchive::~ZipArchive() {
-	for (int i = 0; i < packages.size(); i++) {
-		unzClose(packages[i].zfile);
-	}
-
 	packages.clear();
 }
 

+ 0 - 1
core/io/file_access_zip.h

@@ -47,7 +47,6 @@ public:
 private:
 	struct Package {
 		String filename;
-		unzFile zfile = nullptr;
 	};
 	Vector<Package> packages;