[Mesa-dev] [PATCH] aux/pipe_loader: Don't leak error string on dlopen failure

Aaron Watry awatry at gmail.com
Fri Nov 14 10:31:20 PST 2014


On Fri, Nov 14, 2014 at 12:04 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Fri, Nov 14, 2014 at 12:48 PM, Aaron Watry <awatry at gmail.com> wrote:
>> Signed-off-by: Aaron Watry <awatry at gmail.com>
>> CC: Ilia Mirkin <imirkin at alum.mit.edu>
>>
>> v4: Call dlerror() twice instead of freeing glibc's memory.
>>     Prevents issues on C Libraries that don't malloc the error string.
>> v3: Switch comment to C-Style
>> v2: Use strdup instead of calloc/strcpy
>> ---
>>  src/gallium/auxiliary/pipe-loader/pipe_loader.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
>> index 8e79f85..f103497 100644
>> --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c
>> +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
>> @@ -25,6 +25,8 @@
>>   *
>>   **************************************************************************/
>>
>> +#include <dlfcn.h>
>> +
>>  #include "pipe_loader_priv.h"
>>
>>  #include "util/u_inlines.h"
>> @@ -101,6 +103,10 @@ pipe_loader_find_module(struct pipe_loader_device *dev,
>>           if (lib) {
>>              return lib;
>>           }
>> +
>> +         /* Retrieve the dlerror() str twice. Once to populate the error, twice to clear it. */
>> +        dlerror();
>> +        dlerror();
>
> Is this portable? Perhaps just if PIPE_OS_UNIX or something? (For the
> include as well...)
>
> I could be wrong on that though. But please check :)
>

How about changing dlerror to util_dl_error? It takes care of the
os-portability issues.

--Aaron

>>        }
>>     }
>>
>> --
>> 2.1.0
>>


More information about the mesa-dev mailing list