[PATCH 1/2] helpers: Save a copy to the trapped error, not pointer
Daniel Stone
daniel at fooishbar.org
Sun Nov 4 20:58:42 PST 2012
SetErrorTrap/ReleaseErrorTrap were storing a pointer to the error,
rather than a copy of it. It was pretty liable to getting trashed, so
instead store a copy of our error.
Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
tests/common/helpers.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/common/helpers.cpp b/tests/common/helpers.cpp
index f48a134..3803d26 100644
--- a/tests/common/helpers.cpp
+++ b/tests/common/helpers.cpp
@@ -132,9 +132,9 @@ void DeviceSetEnabled(Display *dpy, int deviceid, bool enabled)
/* Basic error trapping */
static struct {
bool is_trapping;
- XErrorEvent *error;
+ XErrorEvent error;
XErrorHandler prev_error_handler;
-} trap_state = { False, NULL, NULL };
+} trap_state;
static int
ErrorHandler(Display *dpy,
@@ -143,7 +143,7 @@ ErrorHandler(Display *dpy,
if (!trap_state.is_trapping)
ADD_FAILURE() << "Error trap received error while not trapping. WTF?";
- trap_state.error = error;
+ trap_state.error = *error;
return 0;
}
@@ -154,6 +154,7 @@ void SetErrorTrap(Display *dpy) {
XSync(dpy, False);
trap_state.prev_error_handler = XSetErrorHandler(ErrorHandler);
trap_state.is_trapping = True;
+ memset(&trap_state.error, 0, sizeof(trap_state.error));
}
XErrorEvent * ReleaseErrorTrap(Display *dpy) {
@@ -164,8 +165,7 @@ XErrorEvent * ReleaseErrorTrap(Display *dpy) {
XSetErrorHandler(trap_state.prev_error_handler);
trap_state.prev_error_handler = NULL;
- XErrorEvent *error = trap_state.error;
- trap_state.error = NULL;
+ XErrorEvent *error = &trap_state.error;
trap_state.is_trapping = False;
return error;
}
--
1.7.10.4
More information about the xorg-devel
mailing list