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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 7888011: There is a complain from Valgrind about invalid memory access in snd_device_name_hint(-1, ..) // ... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/linux/alsa_wrapper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "media/audio/linux/audio_manager_linux.h" 5 #include "media/audio/linux/audio_manager_linux.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/nix/xdg_util.h" 10 #include "base/nix/xdg_util.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // TODO(ajwong): Make this actually query audio devices. 56 // TODO(ajwong): Make this actually query audio devices.
57 return true; 57 return true;
58 } 58 }
59 59
60 bool AudioManagerLinux::HasAudioInputDevices() { 60 bool AudioManagerLinux::HasAudioInputDevices() {
61 if (!initialized()) { 61 if (!initialized()) {
62 return false; 62 return false;
63 } 63 }
64 64
65 // Constants specified by the ALSA API for device hints. 65 // Constants specified by the ALSA API for device hints.
66 static const int kGetAllDevices = -1;
67 static const char kPcmInterfaceName[] = "pcm"; 66 static const char kPcmInterfaceName[] = "pcm";
68 bool has_device = false; 67 bool has_device = false;
69 void** hints = NULL; 68 void** hints = NULL;
69 int card = -1;
70 70
71 // Use the same approach to find the devices as in 71 // Loop through the sound cards to get Alsa device hints.
72 // AlsaPcmOutputStream::FindDeviceForChannels 72 // Don't use snd_device_name_hint(-1,..) since there is a memory leak inside
Alexander Potapenko 2011/09/13 17:03:04 There is not a memory leak, but an access violatio
xians 2011/09/14 08:12:01 Done.
73 // Get Alsa device hints. 73 // this ALSA API with libasound.so.2.0.0.
74 int error = wrapper_->DeviceNameHint(kGetAllDevices, 74 while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) {
75 kPcmInterfaceName, 75 int error = wrapper_->DeviceNameHint(card,
76 &hints); 76 kPcmInterfaceName,
77 if (error == 0) { 77 &hints);
78 has_device = HasAnyValidAudioInputDevice(hints); 78 if (error == 0) {
79 } else { 79 has_device = HasAnyValidAudioInputDevice(hints);
80 LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error); 80
81 // Destroy the hints now that we're done with it.
82 wrapper_->DeviceNameFreeHint(hints);
83 hints = NULL;
84 } else {
85 LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
86 }
81 } 87 }
82 88
83 // Destroy the hint now that we're done with it.
84 wrapper_->DeviceNameFreeHint(hints);
Raymond Toy (Google) 2011/09/13 17:07:40 Won't there be a real leak now since you don't fre
xians 2011/09/14 08:12:01 In case DeviceNameHint fails, hints should be alwa
85 return has_device; 89 return has_device;
86 } 90 }
87 91
88 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( 92 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream(
89 const AudioParameters& params) { 93 const AudioParameters& params) {
90 // Early return for testing hook. Do this before checking for 94 // Early return for testing hook. Do this before checking for
91 // |initialized_|. 95 // |initialized_|.
92 if (params.format == AudioParameters::AUDIO_MOCK) { 96 if (params.format == AudioParameters::AUDIO_MOCK) {
93 return FakeAudioOutputStream::MakeFakeStream(params); 97 return FakeAudioOutputStream::MakeFakeStream(params);
94 } 98 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return true; 244 return true;
241 } 245 }
242 246
243 return false; 247 return false;
244 } 248 }
245 249
246 // static 250 // static
247 AudioManager* AudioManager::CreateAudioManager() { 251 AudioManager* AudioManager::CreateAudioManager() {
248 return new AudioManagerLinux(); 252 return new AudioManagerLinux();
249 } 253 }
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_wrapper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698