Segfault bug when creating SDLwindow

Hey Everybody,
I was having an issues creating an Ogre3d window then trying to call
SDL_CreateWindowFrom() to create an SDL window. The same code appears to
work currently on another platform so I tried to narrow it down the best I
could. For reference I am using Ubuntu 11.04 with Unity3d.

Specifically in the file src/video/x11/SDL_x11window.c in the function
char * X11_GetWindowTitle(_THIS, Window xwindow) I found a bug. The
function GetWindowTitle assumes that if XGetWindowProperty returns success
it will not return a null pointer. I have modified to check for null
pointers. I have attached a patch file of this change.

In the original it assumes that if the check for _NET_WM_NAME is
successful it will get a valid pointer, which seems reasonable to me, but
turned out not to be the case. So I added checks for null propdata pointers,
so that it will check for an XA_WM_NAME, and if that fails or returns a null
pointer it will then return a copy of a blank string. On my specific setup
it finds a null pointer for _NET_WM_NAME then successfully finds a valid
XA_WM_NAME.

*Original - *------------------------------
char *
X11_GetWindowTitle(_THIS, Window xwindow)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Display *display = data->display;
int status, real_format;
Atom real_type;
unsigned long items_read, items_left;
unsigned char *propdata;
char *title = NULL;

status = XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
            0L, 8192L, False, data->UTF8_STRING, &real_type,

&real_format,
&items_read, &items_left, &propdata);
if (status == Success) {
title = SDL_strdup(SDL_static_cast(
char*, propdata));
XFree(propdata);
} else {
status = XGetWindowProperty(display, xwindow, XA_WM_NAME,
0L, 8192L, False, XA_STRING, &real_type, &real_format,
&items_read, &items_left, &propdata);
if (status == Success) {
title = SDL_iconv_string(“UTF-8”, “”, SDL_static_cast(char*,
propdata), items_read+1);
} else {
title = SDL_strdup("");
}
}
return title;
}

Fixed -

char *
X11_GetWindowTitle(_THIS, Window xwindow)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Display *display = data->display;
int status, real_format;
Atom real_type;
unsigned long items_read, items_left;
unsigned char *propdata;
char *title = NULL;

status = XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
            0L, 8192L, False, data->UTF8_STRING, &real_type,

&real_format,
&items_read, &items_left, &propdata);
if (status == Success && propdata) {
title = SDL_strdup(SDL_static_cast(char*, propdata));
XFree(propdata);
} else {
status = XGetWindowProperty(display, xwindow, XA_WM_NAME,
0L, 8192L, False, XA_STRING, &real_type, &real_format,
&items_read, &items_left, &propdata);
if (status == Success && propdata) {
title = SDL_iconv_string(“UTF-8”, “”, SDL_static_cast(char*,
propdata), items_read+1);
} else {
title = SDL_strdup("");
}
}
return title;
}

Diff -

622c622
< if (status == Success) {

if (status == Success && propdata) {

629c629
< if (status == Success) {

    if (status == Success && propdata) {