Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "net/disk_cache/blockfile/mapped_file.h" | 5 #include "net/disk_cache/blockfile/mapped_file.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 | 11 |
| 12 namespace disk_cache { | 12 namespace disk_cache { |
| 13 | 13 |
| 14 void* MappedFile::Init(const base::FilePath& name, size_t size) { | 14 void* MappedFile::Init(const base::FilePath& name, size_t size) { |
| 15 DCHECK(!init_); | 15 DCHECK(!init_); |
| 16 if (init_ || !File::Init(name)) | 16 if (init_ || !File::Init(name)) |
| 17 return NULL; | 17 return NULL; |
| 18 | 18 |
| 19 if (!size) | 19 if (!size) { |
| 20 size = GetLength(); | 20 size = GetLength(); |
| 21 if (!size) | |
| 22 return NULL; | |
|
danakj
2016/11/29 01:48:01
0 should be okay again for this CL
| |
| 23 } | |
| 21 | 24 |
| 22 buffer_ = malloc(size); | 25 buffer_ = malloc(size); |
| 23 snapshot_ = malloc(size); | 26 snapshot_ = malloc(size); |
| 24 if (buffer_ && snapshot_ && Read(buffer_, size, 0)) { | 27 if (buffer_ && snapshot_ && Read(buffer_, size, 0)) { |
| 25 memcpy(snapshot_, buffer_, size); | 28 memcpy(snapshot_, buffer_, size); |
| 26 } else { | 29 } else { |
| 27 free(buffer_); | 30 free(buffer_); |
| 28 free(snapshot_); | 31 free(snapshot_); |
| 29 buffer_ = snapshot_ = 0; | 32 buffer_ = snapshot_ = 0; |
| 30 } | 33 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 54 return; | 57 return; |
| 55 | 58 |
| 56 if (buffer_ && snapshot_) { | 59 if (buffer_ && snapshot_) { |
| 57 Flush(); | 60 Flush(); |
| 58 } | 61 } |
| 59 free(buffer_); | 62 free(buffer_); |
| 60 free(snapshot_); | 63 free(snapshot_); |
| 61 } | 64 } |
| 62 | 65 |
| 63 } // namespace disk_cache | 66 } // namespace disk_cache |
| OLD | NEW |