Commit 703116cc authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

[mini_installer] Fix file leaks in component build.

In the component build, setup.exe requires its dependent DLLs to
run. In support of this, mini_installer contains all of those DLLs as
extra (uncompressed) resources. These are extracted and placed next to
setup.exe in the work directory.

This CL adds a titch of cleanup code to delete these extracted
resources.

BUG=127233
R=gab@chromium.org

Change-Id: Icf41e3c2535d07dd1ba1888e4d2e5fbcc8f1c934
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2501746
Commit-Queue: Greg Thompson <grt@chromium.org>
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821463}
parent 58e7a87f
...@@ -351,6 +351,23 @@ BOOL CALLBACK WriteResourceToDirectory(HMODULE module, ...@@ -351,6 +351,23 @@ BOOL CALLBACK WriteResourceToDirectory(HMODULE module,
return (resource.IsValid() && full_path.assign(base_path) && return (resource.IsValid() && full_path.assign(base_path) &&
full_path.append(name) && resource.WriteToDisk(full_path.get())); full_path.append(name) && resource.WriteToDisk(full_path.get()));
} }
// An EnumResNameProc callback that deletes the file corresponding to the
// resource |name| from the directory |base_path_ptr| (which must end with a
// path separator).
BOOL CALLBACK DeleteResourceInDirectory(HMODULE module,
const wchar_t* type,
wchar_t* name,
LONG_PTR base_path_ptr) {
PathString full_path;
if (full_path.assign(reinterpret_cast<const wchar_t*>(base_path_ptr)) &&
full_path.append(name)) {
::DeleteFile(full_path.get());
}
return TRUE; // Continue enumeration.
}
#endif #endif
// Finds and writes to disk resources of various types. Returns false // Finds and writes to disk resources of various types. Returns false
...@@ -533,14 +550,23 @@ ProcessExitResult RunSetup(const Configuration& configuration, ...@@ -533,14 +550,23 @@ ProcessExitResult RunSetup(const Configuration& configuration,
RUN_SETUP_FAILED_COULD_NOT_CREATE_PROCESS); RUN_SETUP_FAILED_COULD_NOT_CREATE_PROCESS);
} }
// Deletes given files and working dir. // Deletes the files extracted by UnpackBinaryResources and the work directory
void DeleteExtractedFiles(const wchar_t* base_path, // created by GetWorkDir.
const wchar_t* archive_path, void DeleteExtractedFiles(HMODULE module,
const wchar_t* setup_path) { const PathString& archive_path,
::DeleteFile(archive_path); const PathString& setup_path,
::DeleteFile(setup_path); const PathString& base_path) {
::DeleteFile(archive_path.get());
::DeleteFile(setup_path.get());
#if defined(COMPONENT_BUILD)
// Delete the modules in a component build extracted for use by setup.exe.
::EnumResourceNames(module, kBinResourceType, DeleteResourceInDirectory,
reinterpret_cast<LONG_PTR>(base_path.get()));
#endif
// Delete the temp dir (if it is empty, otherwise fail). // Delete the temp dir (if it is empty, otherwise fail).
::RemoveDirectory(base_path); ::RemoveDirectory(base_path.get());
} }
// Returns true if the supplied path supports ACLs. // Returns true if the supplied path supports ACLs.
...@@ -778,7 +804,7 @@ ProcessExitResult WMain(HMODULE module) { ...@@ -778,7 +804,7 @@ ProcessExitResult WMain(HMODULE module) {
exit_code = RunSetup(configuration, archive_path.get(), setup_path.get()); exit_code = RunSetup(configuration, archive_path.get(), setup_path.get());
if (configuration.should_delete_extracted_files()) if (configuration.should_delete_extracted_files())
DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get()); DeleteExtractedFiles(module, archive_path, setup_path, base_path);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (exit_code.IsSuccess()) { if (exit_code.IsSuccess()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment