diff options
author | raphael.kubo.da.costa <raphael.kubo.da.costa@intel.com> | 2015-02-24 04:44:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-24 12:45:17 +0000 |
commit | a755ee0ae677fe872fc83b52752a7c11f0a70cde (patch) | |
tree | 7330d97ae6d00133461b709a9275574680a3a457 /media | |
parent | 81c05e116617d13b4b708792f0d2eb21ede1c829 (diff) | |
download | chromium_src-a755ee0ae677fe872fc83b52752a7c11f0a70cde.zip chromium_src-a755ee0ae677fe872fc83b52752a7c11f0a70cde.tar.gz chromium_src-a755ee0ae677fe872fc83b52752a7c11f0a70cde.tar.bz2 |
WebAudioMediaCodecBridge: Close file descriptor on error.
Use a base::ScopedFD instead of a plain integer so we do not have to
worry about manually closing SaveEncodedAudioToFile()'s temporary file
description on error cases.
Review URL: https://codereview.chromium.org/942033002
Cr-Commit-Position: refs/heads/master@{#317786}
Diffstat (limited to 'media')
-rw-r--r-- | media/base/android/webaudio_media_codec_bridge.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/media/base/android/webaudio_media_codec_bridge.cc b/media/base/android/webaudio_media_codec_bridge.cc index 160614b..12861d6 100644 --- a/media/base/android/webaudio_media_codec_bridge.cc +++ b/media/base/android/webaudio_media_codec_bridge.cc @@ -15,6 +15,7 @@ #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/basictypes.h" +#include "base/files/scoped_file.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "base/stl_util.h" @@ -64,13 +65,13 @@ int WebAudioMediaCodecBridge::SaveEncodedAudioToFile( // Open the file and unlink it, so that it will be actually removed // when we close the file. - int fd = open(temporaryFile.c_str(), O_RDWR); + base::ScopedFD fd(open(temporaryFile.c_str(), O_RDWR)); if (unlink(temporaryFile.c_str())) { VLOG(0) << "Couldn't unlink temp file " << temporaryFile << ": " << strerror(errno); } - if (fd < 0) { + if (!fd.is_valid()) { return -1; } @@ -83,15 +84,15 @@ int WebAudioMediaCodecBridge::SaveEncodedAudioToFile( return -1; } - if (static_cast<uint32_t>(write(fd, encoded_data.memory(), data_size_)) + if (static_cast<uint32_t>(write(fd.get(), encoded_data.memory(), data_size_)) != data_size_) { VLOG(0) << "Failed to write all audio data to temp file!"; return -1; } - lseek(fd, 0, SEEK_SET); + lseek(fd.get(), 0, SEEK_SET); - return fd; + return fd.release(); } bool WebAudioMediaCodecBridge::DecodeInMemoryAudioFile() { |