The trouble is that to be completely correct, you have to Free the values you Allocated into previous members of the ids and keys arrays, as well as the arrays themselves. That means a for-loop over only the valid members of those arrays, and it turns into quite a lot of code for an error path that will never be executed anyway.
You should either do it correctly or not at all. Your choice :)
Okay, I removed all the checks ...
You can use TRACE instead, it doesn't really matter. It's just so we know what went wrong is someone doesn't get all the devices they expect. Better to have too much information than too little.
Warn added.
My suggested change sets def_index to the index of the ALSA device "default" (or "pulse" (or, finally, just the first device)) which is much more likely to be what the user expects.
AFAIK, ALSA always have a "default" device, so I think there is not need to check for it presence. I just add it at zero place, like it was before.
I just meant that it wasn't correct for sending to wine-patches. Basically, just make your changes as a commit in Git, and then use git-format-patch to create a patch file. You can attach that to your email and send it.
Take a look at some mails here http://source.winehq.org/patches/ for an idea of what your mail (or attachment) should look like when you send it.
Maybe I can just attach a patch to my bugreport?