Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1195)

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 683913009: Eliminate resource leaks from zip::ZipFiles and (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void ChromeContentUtilityClient::OnDecodeImage( 242 void ChromeContentUtilityClient::OnDecodeImage(
243 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) { 243 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) {
244 DecodeImageAndSend(encoded_data, shrink_to_fit); 244 DecodeImageAndSend(encoded_data, shrink_to_fit);
245 } 245 }
246 246
247 #if defined(OS_CHROMEOS) 247 #if defined(OS_CHROMEOS)
248 void ChromeContentUtilityClient::OnCreateZipFile( 248 void ChromeContentUtilityClient::OnCreateZipFile(
249 const base::FilePath& src_dir, 249 const base::FilePath& src_dir,
250 const std::vector<base::FilePath>& src_relative_paths, 250 const std::vector<base::FilePath>& src_relative_paths,
251 const base::FileDescriptor& dest_fd) { 251 const base::FileDescriptor& dest_fd) {
252 base::File dest_file(dest_fd);
satorux1 2014/11/12 07:04:43 This is needed to close the file descriptor, right
jeremyspiegel 2014/11/12 08:52:51 Yes thanks, that is what I was looking for.
252 bool succeeded = true; 253 bool succeeded = true;
253 254
254 // Check sanity of source relative paths. Reject if path is absolute or 255 // Check sanity of source relative paths. Reject if path is absolute or
255 // contains any attempt to reference a parent directory ("../" tricks). 256 // contains any attempt to reference a parent directory ("../" tricks).
256 for (std::vector<base::FilePath>::const_iterator iter = 257 for (std::vector<base::FilePath>::const_iterator iter =
257 src_relative_paths.begin(); iter != src_relative_paths.end(); 258 src_relative_paths.begin(); iter != src_relative_paths.end();
258 ++iter) { 259 ++iter) {
259 if (iter->IsAbsolute() || iter->ReferencesParent()) { 260 if (iter->IsAbsolute() || iter->ReferencesParent()) {
260 succeeded = false; 261 succeeded = false;
261 break; 262 break;
262 } 263 }
263 } 264 }
264 265
265 if (succeeded) 266 if (succeeded)
266 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); 267 succeeded = zip::ZipFiles(
268 src_dir, src_relative_paths, dest_file.GetPlatformFile());
267 269
268 if (succeeded) 270 if (succeeded)
269 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); 271 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded());
270 else 272 else
271 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); 273 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed());
272 ReleaseProcessIfNeeded(); 274 ReleaseProcessIfNeeded();
273 } 275 }
274 #endif // defined(OS_CHROMEOS) 276 #endif // defined(OS_CHROMEOS)
275 277
276 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage( 278 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 const std::string& mime_type, int64 total_size, bool get_attached_images) { 348 const std::string& mime_type, int64 total_size, bool get_attached_images) {
347 // Only one IPCDataSource may be created and added to the list of handlers. 349 // Only one IPCDataSource may be created and added to the list of handlers.
348 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); 350 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size);
349 handlers_.push_back(source); 351 handlers_.push_back(source);
350 352
351 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( 353 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser(
352 source, mime_type, get_attached_images); 354 source, mime_type, get_attached_images);
353 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); 355 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser)));
354 } 356 }
355 #endif 357 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698