diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc index ab33448cc36bd..fed36966a97c9 100644 --- a/base/platform_file_posix.cc +++ b/base/platform_file_posix.cc @@ -59,7 +59,8 @@ PlatformFile CreatePlatformFile(const FilePath& name, int flags, !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { NOTREACHED(); errno = EOPNOTSUPP; - *error_code = error_code ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; + if (error_code) + *error_code = PLATFORM_FILE_ERROR_FAILED; return kInvalidPlatformFileValue; } diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index 1580487d17056..f81d88c3425a3 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -150,14 +150,20 @@ bool SharedMemory::CreateNamed(const std::string& name, if (fp && fix_size) { // Get current size. struct stat stat; - if (fstat(fileno(fp), &stat) != 0) + if (fstat(fileno(fp), &stat) != 0) { + file_util::CloseFile(fp); return false; + } const uint32 current_size = stat.st_size; if (current_size != size) { - if (HANDLE_EINTR(ftruncate(fileno(fp), size)) != 0) + if (HANDLE_EINTR(ftruncate(fileno(fp), size)) != 0) { + file_util::CloseFile(fp); return false; - if (fseeko(fp, size, SEEK_SET) != 0) + } + if (fseeko(fp, size, SEEK_SET) != 0) { + file_util::CloseFile(fp); return false; + } } created_size_ = size; }