[Mesa-dev] [PATCH 4/4] aux/pipe_loader: Don't leak dlerror string on dlopen failure
Aaron Watry
awatry at gmail.com
Thu Aug 21 09:06:45 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>
---
src/gallium/auxiliary/pipe-loader/pipe_loader.c | 5 +++++
src/gallium/auxiliary/util/u_dl.c | 13 +++++++++++--
2 files changed, 16 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..7f9231f 100644
--- a/src/gallium/auxiliary/util/u_dl.c
+++ b/src/gallium/auxiliary/util/u_dl.c
@@ -39,6 +39,7 @@
#include "u_dl.h"
#include "u_pointer.h"
+#include "u_memory.h"
struct util_dl_library *
@@ -87,8 +88,16 @@ util_dl_error(void)
#if defined(PIPE_OS_UNIX)
return dlerror();
#elif defined(PIPE_OS_WINDOWS)
- return "unknown error";
+ char *error = CALLOC(14, sizeof(char));
+ if (error == NULL) {
+ return NULL;
+ }
+ return strcpy(error, "unknown error");
#else
- return "unknown error";
+ char *error = CALLOC(14, sizeof(char));
+ if (error == NULL) {
+ return NULL;
+ }
+ return strcpy(error, "unknown error");
#endif
}
--
1.9.1
More information about the mesa-dev
mailing list