Troubleshooting segfault in AudioDeviceManager::initialise()

I have an application that initializes the built-in audio hardware upon startup, which sometimes results in segfaults when enumerating the available audio devices. In the past, closing all applications and running “sudo alsa force-reload” has fixed the problem, but on a Dell Optiplex 9010 (running 64-bit Ubuntu 12.04) it doesn’t seem to help. Any recommendations for troubleshooting uncooperative audio hardware?

What’s the stack trace? Is it something that the juce code is failing to handle, or is it the actual drivers that are segfaulting?

The stack trace is pasted below. As far as your question goes, I’m just a user trying to help the developers debug this (it’s my machine the code is crashing on), so I don’t know. Please let me know if there’s any additional info I can provide, though.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5e08640 in __strcpy_chk () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff5e08640 in __strcpy_chk () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff73d36c0 in ?? () from /usr/lib/x86_64-linux-gnu/libasound.so.2
#2 0x00007ffff73d4723 in snd_device_name_hint () from /usr/lib/x86_64-linux-gnu/libasound.so.2
#3 0x00000000004eb3ad in juce::(anonymous namespace)::ALSAAudioIODeviceType::enumerateAlsaPCMDevices (
this=0xf51910) at …/…/JuceLibraryCode/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:1125
#4 0x00000000004ebf1e in scanForDevices (this=0xf51910)
at …/…/JuceLibraryCode/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:931
#5 juce::(anonymous namespace)::ALSAAudioIODeviceType::scanForDevices (this=0xf51910)
at …/…/JuceLibraryCode/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:915
#6 0x00000000004f4cd5 in juce::AudioDeviceManager::scanDevicesIfNeeded (this=0xf51570)
at …/…/JuceLibraryCode/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp:323
#7 0x00000000004f5e90 in scanDevicesIfNeeded (this=0xf51570)
at …/…/JuceLibraryCode/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp:316
#8 juce::AudioDeviceManager::initialise (this=0xf51570, numInputChannelsNeeded=0, numOutputChannelsNeeded=2,
e=0x0, selectDefaultDeviceOnFailure=true, preferredDefaultDeviceName=…, preferredSetupOptions=0x0)
at …/…/JuceLibraryCode/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp:189
#9 0x000000000041f1ec in AudioComponent::AudioComponent (this=0xf51570)
at …/…/Source/Audio/AudioComponent.cpp:36
#10 0x00000000004c6e79 in MainWindow::MainWindow (this=0xf42670) at …/…/Source/MainWindow.cpp:45
#11 0x00000000004c753f in OpenEphysApplication::initialise (this=0xf406a0, commandLine=…)
at …/…/Source/Main.cpp:78
#12 0x0000000000728547 in juce::JUCEApplication::initialiseApp (this=0xf406a0)
at …/…/JuceLibraryCode/modules/juce_gui_basics/application/juce_Application.cpp:180
#13 0x000000000040e84c in juce::JUCEApplication::main ()
at …/…/JuceLibraryCode/modules/juce_gui_basics/application/juce_Application.cpp:235
#14 0x00007ffff5d2176d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#15 0x000000000040f539 in _start ()
(gdb)

Nasty - it’s crashing inside an ALSA function, but the juce code that calls it is just:

snd_device_name_hint (-1, "pcm", &hints)

So there’s no possibility of any incorrect state being passed to the function - if it crashes, then it must be an internal ALSA/driver bug, I think.

Thanks. My alsa drivers were up to date at the package level, but I downloaded the source and built the latest version, and that worked, so I guess that was the issue.

There are quite ugly bugs in some alsa versions, for example on my debian , aplay -l runs fine, but when I run it in valgrind it screams about invalid memory read in functions related to snd_device_name_hint – so that’s probably the same issue.