summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 03:59:35 +0000
committerxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 03:59:35 +0000
commit7d5ad4239974cad5843fb605488a8c833716e56c (patch)
tree69f4238224ecc2495f5a1fdf7ca027e4aa9c434a
parente1ece30375b913301c3a1c85abe13e3ef51a0f44 (diff)
downloadchromium_src-7d5ad4239974cad5843fb605488a8c833716e56c.zip
chromium_src-7d5ad4239974cad5843fb605488a8c833716e56c.tar.gz
chromium_src-7d5ad4239974cad5843fb605488a8c833716e56c.tar.bz2
There is a complain from Valgrind about invalid memory access in snd_device_name_hint(-1, ..) // -1 means all cards.
It looks like the problem is actually because we use -1 to loop through all the soundcards. And this patch will loop through the soundcard manually, which should resolve the Valgrind problem. Bug=96207 Test=media_unittests with Valgrind Review URL: http://codereview.chromium.org/7888011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101240 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/audio/linux/alsa_wrapper.cc4
-rw-r--r--media/audio/linux/alsa_wrapper.h1
-rw-r--r--media/audio/linux/audio_manager_linux.cc32
-rw-r--r--tools/valgrind/memcheck/suppressions.txt21
4 files changed, 23 insertions, 35 deletions
diff --git a/media/audio/linux/alsa_wrapper.cc b/media/audio/linux/alsa_wrapper.cc
index 563bccb..69b703e 100644
--- a/media/audio/linux/alsa_wrapper.cc
+++ b/media/audio/linux/alsa_wrapper.cc
@@ -29,6 +29,10 @@ int AlsaWrapper::DeviceNameFreeHint(void** hints) {
return snd_device_name_free_hint(hints);
}
+int AlsaWrapper::CardNext(int* rcard) {
+ return snd_card_next(rcard);
+}
+
int AlsaWrapper::PcmClose(snd_pcm_t* handle) {
return snd_pcm_close(handle);
}
diff --git a/media/audio/linux/alsa_wrapper.h b/media/audio/linux/alsa_wrapper.h
index efe93d0..85cf68a 100644
--- a/media/audio/linux/alsa_wrapper.h
+++ b/media/audio/linux/alsa_wrapper.h
@@ -19,6 +19,7 @@ class MEDIA_EXPORT AlsaWrapper {
virtual int DeviceNameHint(int card, const char* iface, void*** hints);
virtual char* DeviceNameGetHint(const void* hint, const char* id);
virtual int DeviceNameFreeHint(void** hints);
+ virtual int CardNext(int* rcard);
virtual int PcmOpen(snd_pcm_t** handle, const char* name,
snd_pcm_stream_t stream, int mode);
diff --git a/media/audio/linux/audio_manager_linux.cc b/media/audio/linux/audio_manager_linux.cc
index caab797..930c6b2 100644
--- a/media/audio/linux/audio_manager_linux.cc
+++ b/media/audio/linux/audio_manager_linux.cc
@@ -63,25 +63,29 @@ bool AudioManagerLinux::HasAudioInputDevices() {
}
// Constants specified by the ALSA API for device hints.
- static const int kGetAllDevices = -1;
static const char kPcmInterfaceName[] = "pcm";
bool has_device = false;
void** hints = NULL;
-
- // Use the same approach to find the devices as in
- // AlsaPcmOutputStream::FindDeviceForChannels
- // Get Alsa device hints.
- int error = wrapper_->DeviceNameHint(kGetAllDevices,
- kPcmInterfaceName,
- &hints);
- if (error == 0) {
- has_device = HasAnyValidAudioInputDevice(hints);
- } else {
- LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
+ int card = -1;
+
+ // Loop through the sound cards to get Alsa device hints.
+ // Don't use snd_device_name_hint(-1,..) since there is a access violation
+ // inside this ALSA API with libasound.so.2.0.0.
+ while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) {
+ int error = wrapper_->DeviceNameHint(card,
+ kPcmInterfaceName,
+ &hints);
+ if (error == 0) {
+ has_device = HasAnyValidAudioInputDevice(hints);
+
+ // Destroy the hints now that we're done with it.
+ wrapper_->DeviceNameFreeHint(hints);
+ hints = NULL;
+ } else {
+ LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
+ }
}
- // Destroy the hint now that we're done with it.
- wrapper_->DeviceNameFreeHint(hints);
return has_device;
}
diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt
index 2bc604b..6a9dbd4 100644
--- a/tools/valgrind/memcheck/suppressions.txt
+++ b/tools/valgrind/memcheck/suppressions.txt
@@ -4761,27 +4761,6 @@
fun:_ZN27ScopedRunnableMethodFactoryIN3net21HttpStreamFactoryImpl3JobEE14RunnableMethodIMS2_FvvE6Tuple0E3RunEv
}
{
- bug_96207_a
- Memcheck:Addr1
- ...
- fun:snd_device_name_hint
- fun:_ZN11AlsaWrapper14DeviceNameHintEiPKcPPPv
-}
-{
- bug_96207_b
- Memcheck:Addr4
- ...
- fun:snd_device_name_hint
- fun:_ZN11AlsaWrapper14DeviceNameHintEiPKcPPPv
-}
-{
- bug_96207_c
- Memcheck:Addr4
- ...
- fun:snd_config_iterator_next
- fun:_ZN11AlsaWrapper14DeviceNameHintEiPKcPPPv
-}
-{
bug_96295
Memcheck:Leak
fun:_Znw*