From 7a70694fa2a3fc21dcabc6e46a2c57e751354b6e Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 12 Nov 2013 11:56:43 +0900 Subject: [PATCH 1/2] Fix unsafe use of CString::with_ref Sometimes the C string would get freed before XOpenDisplay was done with it, producing a garbage display string and a null Display*. Also switch to with_c_str because it will stack-allocate for the common case of small strings (doesn't really matter here, but why not). --- platform/linux/surface.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/linux/surface.rs b/platform/linux/surface.rs index 5ce3b7f..7c5b0cd 100644 --- a/platform/linux/surface.rs +++ b/platform/linux/surface.rs @@ -42,7 +42,9 @@ impl NativePaintingGraphicsContext { #[fixed_stack_segment] pub fn from_metadata(metadata: &NativeGraphicsMetadata) -> NativePaintingGraphicsContext { unsafe { - let display = XOpenDisplay(metadata.display.to_c_str().with_ref(|c_str| c_str)); + let display = do metadata.display.with_c_str |c_str| { + XOpenDisplay(c_str) + }; // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. From 456f154ec7a83391d2ce915bbbe23fdd719e0c50 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 12 Nov 2013 13:57:23 +0900 Subject: [PATCH 2/2] Check for XOpenDisplay() failure --- platform/linux/surface.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/linux/surface.rs b/platform/linux/surface.rs index 7c5b0cd..8881f88 100644 --- a/platform/linux/surface.rs +++ b/platform/linux/surface.rs @@ -46,6 +46,10 @@ impl NativePaintingGraphicsContext { XOpenDisplay(c_str) }; + if display.is_null() { + fail!("XOpenDisplay() failed!"); + } + // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let compositor_visual_info =