[Openal-devel] ALC_ENUMERATE_ALL_EXT and pluggable sound devices

Chris Robinson chris.kcat at gmail.com
Thu Sep 24 13:18:28 PDT 2009


On Thursday 24 September 2009 12:43:17 pm Guilherme Balena Versiani wrote:
> > First is (obviously) to make sure you don't leak the previous strings
> > (change the malloc calls to realloc, or free the old pointers first).
> > Also be careful that querying the default devices will also trigger
> > rebuilding the list. (...)
> 
> I take care of this. But I didn't make any cosmetic changes like you
> mentioned, breaking up *BuildDeviceList* function, as my work is just to
> put it working and not maintain the code... After you validate that this
> code is fine, and if really want that, I send you another patch.

Just to clarify, I'm not the one that maintains the router. That would be 
Daniel Peacock.

Also, those things I mentioned aren't merely cosmetic changes. You can't free 
and rebuild the lists for the device types that aren't being queried.. 
otherwise the application can be holding pointers that become invalid, and it 
can crash if it tries to use them. Eg..

const char *caplist = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
const char *devlist = alcGetString(NULL, ALC_DEVICE_SPECIFIER);

while(*devlist) {
    printf("%s\n", devlist);
    devlist += strlen(devlist)+1;
}
while(*caplist) { // crash; the capture device list was freed and allocated
                  // somewhere else during the ALC_DEVICE_SPECIFIER query
    printf("%s\n", caplist);
    caplist += strlen(caplist)+1;
}

Only the list being queried should be rebuilt. It's the same issue with 
querying the default device.. only the default device string should be redone, 
otherwise the other strings and lists the app is holding become invalid and 
will crash when used.

> What I done:
> 
>     - In the start of *BuildDeviceList* there were a clause verifying
> first if the global variables was initialized. I just cleaned up them
> using free() and set them to NULL: *g_pDeviceList*,
> *g_pCaptureDeviceList*, and *g_pAllDevicesList*, and force their
> initialization every time *BuildDeviceList* is called.

You need to take care of the default device strings, too. Otherwise they're 
leaked when FindDevice allocates new memory for them.


More information about the Openal-devel mailing list