[Mesa-dev] [PATCH] aux/pipe_loader: Don't leak dlerror string on dlopen failure
Aaron Watry
awatry at gmail.com
Thu Aug 21 09:24:41 PDT 2014
dlopen allocates a string on dlopen failure which is retrieved via dlerror. In
order to free that string, you need to retrieve and then free it.
In order to keep things legit the windows/other util_dl_error paths allocate
and then copy their error message into a buffer as well.
Signed-off-by: Aaron Watry <awatry at gmail.com>
CC: Ilia Mirkin <imirkin at alum.mit.edu>
v2: Use strdup instead of calloc/strcpy
---
src/gallium/auxiliary/pipe-loader/pipe_loader.c | 5 +++++
src/gallium/auxiliary/util/u_dl.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
index 8e79f85..bf3acca 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,9 @@ pipe_loader_find_module(struct pipe_loader_device *dev,
if (lib) {
return lib;
}
+
+ //Retrieve the dlerror() str so that it can be freed properly
+ FREE(util_dl_error());
}
}
diff --git a/src/gallium/auxiliary/util/u_dl.c b/src/gallium/auxiliary/util/u_dl.c
index aca435d..00c4d7c 100644
--- a/src/gallium/auxiliary/util/u_dl.c
+++ b/src/gallium/auxiliary/util/u_dl.c
@@ -87,8 +87,8 @@ util_dl_error(void)
#if defined(PIPE_OS_UNIX)
return dlerror();
#elif defined(PIPE_OS_WINDOWS)
- return "unknown error";
+ return strdup("unknown error");
#else
- return "unknown error";
+ return strdup("unknown error");
#endif
}
--
1.9.1
More information about the mesa-dev
mailing list