Skip to content

Commit 5259aeb

Browse files
committed
Display: fix segfault when using libxrandr
Fix #544
1 parent e51999e commit 5259aeb

File tree

1 file changed

+9
-4
lines changed
  • src/detection/displayserver/linux

1 file changed

+9
-4
lines changed

src/detection/displayserver/linux/xlib.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef struct XrandrData
116116
{
117117
FF_LIBRARY_SYMBOL(XInternAtom)
118118
FF_LIBRARY_SYMBOL(XGetAtomName);
119+
FF_LIBRARY_SYMBOL(XFree);
119120
FF_LIBRARY_SYMBOL(XRRGetScreenInfo)
120121
FF_LIBRARY_SYMBOL(XRRConfigCurrentConfiguration)
121122
FF_LIBRARY_SYMBOL(XRRConfigCurrentRate)
@@ -207,9 +208,11 @@ static bool xrandrHandleOutput(XrandrData* data, RROutput output, FFstrbuf* name
207208
Atom atomEdid = data->ffXInternAtom(data->display, "EDID", true);
208209
if (atomEdid != None)
209210
{
210-
unsigned long nitems = 0;
211+
int actual_format = 0;
212+
unsigned long nitems = 0, bytes_after = 0;
213+
Atom actual_type = None;
211214
uint8_t* edidData = NULL;
212-
if (data->ffXRRGetOutputProperty(data->display, output, atomEdid, 0, 100, 0, 0, AnyPropertyType, NULL, NULL, &nitems, NULL, &edidData) == Success)
215+
if (data->ffXRRGetOutputProperty(data->display, output, atomEdid, 0, 100, false, false, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &edidData) == Success)
213216
{
214217
if (nitems >= 128)
215218
{
@@ -228,8 +231,9 @@ static bool xrandrHandleOutput(XrandrData* data, RROutput output, FFstrbuf* name
228231
static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo)
229232
{
230233
bool foundOutput = false;
231-
232-
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(data->ffXGetAtomName(data->display, monitorInfo->name));
234+
char* xname = data->ffXGetAtomName(data->display, monitorInfo->name);
235+
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(xname);
236+
data->ffXFree(xname);
233237
for(int i = 0; i < monitorInfo->noutput; i++)
234238
{
235239
if(xrandrHandleOutput(data, monitorInfo->outputs[i], &name, monitorInfo->primary))
@@ -341,6 +345,7 @@ void ffdsConnectXrandr(FFDisplayServerResult* result)
341345

342346
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XInternAtom,);
343347
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XGetAtomName,);
348+
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XFree,);
344349
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRGetScreenInfo,)
345350
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRConfigCurrentRate,);
346351
FF_LIBRARY_LOAD_SYMBOL_VAR(xrandr, data, XRRConfigCurrentConfiguration,);

0 commit comments

Comments
 (0)