diff options
-rw-r--r-- | dbus/dbus-internals.h | 22 | ||||
-rw-r--r-- | tools/dbus-launch-x11.c | 21 |
2 files changed, 42 insertions, 1 deletions
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 96df3ff7..1272e8c5 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -466,6 +466,28 @@ dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str, #define _DBUS_STRINGIFY(x) #x #define _DBUS_FILE_LINE __FILE__ ":" _DBUS_STRINGIFY(__LINE__) +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +/* MSVC defines __SANITIZE_ADDRESS__, but does not provide the special + * builtins associated with it. */ +#if ((defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)) && \ + !defined(_MSC_VER)) +# include <sanitizer/lsan_interface.h> +/* Defined if we are building with AddressSanitizer */ +# define _DBUS_ADDRESS_SANITIZER +/* Ignore memory allocations until the next _DBUS_END_IGNORE_LEAKS when + * checking for memory leaks */ +# define _DBUS_BEGIN_IGNORE_LEAKS __lsan_disable () +/* End the scope of a previous _DBUS_BEGIN_IGNORE_LEAKS */ +# define _DBUS_END_IGNORE_LEAKS __lsan_enable () +#else +# undef _DBUS_ADDRESS_SANITIZER +# define _DBUS_BEGIN_IGNORE_LEAKS do { } while (0) +# define _DBUS_END_IGNORE_LEAKS do { } while (0) +#endif + DBUS_END_DECLS #endif /* DBUS_INTERNALS_H */ diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c index 0b5d2928..48ab51d8 100644 --- a/tools/dbus-launch-x11.c +++ b/tools/dbus-launch-x11.c @@ -37,6 +37,8 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> +#include "dbus/dbus-internals.h" + Display *xdisplay = NULL; static Atom selection_atom; static Atom address_atom; @@ -451,7 +453,24 @@ x11_save_address (char *address, pid_t pid, long *wid) int x11_init (void) { - return open_x11 () != NULL && init_x_atoms (xdisplay); + int ok; + + /* + * The X11 connection is opened and never closed. Because dbus-launch + * forks and continues to run non-trivial code in a forked child, it is + * not clear whether (or where) it would be safe to close it; instead, we + * leave it open until process exit, at which point the socket is cleaned + * up by the kernel. + * + * Any memory allocated for the X11 connection is only allocated once per + * run of dbus-launch, so there's no need to keep track of it, and we can + * silence memory leak warnings from AddressSanitizer as uninteresting. + */ + _DBUS_BEGIN_IGNORE_LEAKS; + ok = open_x11 () != NULL && init_x_atoms (xdisplay); + _DBUS_END_IGNORE_LEAKS; + + return ok; } void |