Fixed memory leak.

This commit is contained in:
Armin Novak 2018-01-22 15:45:27 +01:00
parent bab902f599
commit 7f75b57fd6
1 changed files with 71 additions and 61 deletions

View File

@ -57,8 +57,8 @@ int xf_list_monitors(xfContext* xfc)
Display* display;
int major, minor;
int i, nmonitors = 0;
display = XOpenDisplay(NULL);
if (!display)
{
WLog_ERR(TAG, "failed to open X display");
@ -66,49 +66,53 @@ int xf_list_monitors(xfContext* xfc)
}
#if defined(USABLE_XRANDR)
if (XRRQueryExtension(xfc->display, &major, &minor) && (XRRQueryVersion(xfc->display, &major, &minor) == True) &&
(major * 100 + minor >= 105))
if (XRRQueryExtension(xfc->display, &major, &minor) &&
(XRRQueryVersion(xfc->display, &major, &minor) == True) &&
(major * 100 + minor >= 105))
{
XRRMonitorInfo *monitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &nmonitors);
XRRMonitorInfo* monitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1,
&nmonitors);
for (i = 0; i < nmonitors; i++)
{
printf(" %s [%d] %hdx%hd\t+%hd+%hd\n",
monitors[i].primary ? "*" : " ", i,
monitors[i].width, monitors[i].height,
monitors[i].x, monitors[i].y);
monitors[i].primary ? "*" : " ", i,
monitors[i].width, monitors[i].height,
monitors[i].x, monitors[i].y);
}
XRRFreeMonitors(monitors);
} else
}
else
#endif
#ifdef WITH_XINERAMA
if (XineramaQueryExtension(display, &major, &minor))
{
if (XineramaIsActive(display))
if (XineramaQueryExtension(display, &major, &minor))
{
XineramaScreenInfo* screen = XineramaQueryScreens(display, &nmonitors);
for (i = 0; i < nmonitors; i++)
if (XineramaIsActive(display))
{
printf(" %s [%d] %hdx%hd\t+%hd+%hd\n",
(i == 0) ? "*" : " ", i,
screen[i].width, screen[i].height,
screen[i].x_org, screen[i].y_org);
XineramaScreenInfo* screen = XineramaQueryScreens(display, &nmonitors);
for (i = 0; i < nmonitors; i++)
{
printf(" %s [%d] %hdx%hd\t+%hd+%hd\n",
(i == 0) ? "*" : " ", i,
screen[i].width, screen[i].height,
screen[i].x_org, screen[i].y_org);
}
XFree(screen);
}
XFree(screen);
}
} else
else
#else
{
Screen* screen = ScreenOfDisplay(display, DefaultScreen(display));
printf(" * [0] %dx%d\t+0+0\n", WidthOfScreen(screen), HeightOfScreen(screen));
}
#endif
XCloseDisplay(display);
#endif
XCloseDisplay(display);
return 0;
}
@ -145,10 +149,9 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
int major, minor;
#endif
#if defined(USABLE_XRANDR)
XRRMonitorInfo *rrmonitors = NULL;
XRRMonitorInfo* rrmonitors = NULL;
BOOL useXRandr = FALSE;
#endif
vscreen = &xfc->vscreen;
*pMaxWidth = settings->DesktopWidth;
*pMaxHeight = settings->DesktopHeight;
@ -160,10 +163,13 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
mouse_x = mouse_y = 0;
#if defined(USABLE_XRANDR)
if (XRRQueryExtension(xfc->display, &major, &minor) && (XRRQueryVersion(xfc->display, &major, &minor) == True) &&
(major * 100 + minor >= 105))
if (XRRQueryExtension(xfc->display, &major, &minor) &&
(XRRQueryVersion(xfc->display, &major, &minor) == True) &&
(major * 100 + minor >= 105))
{
XRRMonitorInfo *rrmonitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &vscreen->nmonitors);
XRRMonitorInfo* rrmonitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1,
&vscreen->nmonitors);
if (vscreen->nmonitors > 16)
vscreen->nmonitors = 0;
@ -179,40 +185,42 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
vscreen->monitors[i].primary = rrmonitors[i].primary > 0;
}
}
XRRFreeMonitors(rrmonitors);
useXRandr = TRUE;
} else
}
else
#endif
#ifdef WITH_XINERAMA
if (XineramaQueryExtension(xfc->display, &major, &minor) && XineramaIsActive(xfc->display))
{
XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &vscreen->nmonitors);
if (vscreen->nmonitors > 16)
vscreen->nmonitors = 0;
if (vscreen->nmonitors)
if (XineramaQueryExtension(xfc->display, &major, &minor) && XineramaIsActive(xfc->display))
{
for (i = 0; i < vscreen->nmonitors; i++)
{
vscreen->monitors[i].area.left = screenInfo[i].x_org;
vscreen->monitors[i].area.top = screenInfo[i].y_org;
vscreen->monitors[i].area.right = screenInfo[i].x_org + screenInfo[i].width - 1;
vscreen->monitors[i].area.bottom = screenInfo[i].y_org + screenInfo[i].height - 1;
XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &vscreen->nmonitors);
/* Determine which monitor that the mouse cursor is on */
if ((mouse_x >= vscreen->monitors[i].area.left) &&
(mouse_x <= vscreen->monitors[i].area.right) &&
(mouse_y >= vscreen->monitors[i].area.top) &&
(mouse_y <= vscreen->monitors[i].area.bottom))
current_monitor = i;
if (vscreen->nmonitors > 16)
vscreen->nmonitors = 0;
if (vscreen->nmonitors)
{
for (i = 0; i < vscreen->nmonitors; i++)
{
vscreen->monitors[i].area.left = screenInfo[i].x_org;
vscreen->monitors[i].area.top = screenInfo[i].y_org;
vscreen->monitors[i].area.right = screenInfo[i].x_org + screenInfo[i].width - 1;
vscreen->monitors[i].area.bottom = screenInfo[i].y_org + screenInfo[i].height - 1;
/* Determine which monitor that the mouse cursor is on */
if ((mouse_x >= vscreen->monitors[i].area.left) &&
(mouse_x <= vscreen->monitors[i].area.right) &&
(mouse_y >= vscreen->monitors[i].area.top) &&
(mouse_y <= vscreen->monitors[i].area.bottom))
current_monitor = i;
}
}
XFree(screenInfo);
}
XFree(screenInfo);
}
#endif
xfc->fullscreenMonitors.top = xfc->fullscreenMonitors.bottom =
xfc->fullscreenMonitors.left = xfc->fullscreenMonitors.right = 0;
@ -297,30 +305,30 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
/* Create array of all active monitors by taking into account monitors requested on the command-line */
for (i = 0; i < vscreen->nmonitors; i++)
{
MONITOR_ATTRIBUTES *attrs;
MONITOR_ATTRIBUTES* attrs;
if (!xf_is_monitor_id_active(xfc, i))
continue;
settings->MonitorDefArray[nmonitors].x = vscreen->monitors[i].area.left;
settings->MonitorDefArray[nmonitors].y = vscreen->monitors[i].area.top;
settings->MonitorDefArray[nmonitors].width =
MIN(vscreen->monitors[i].area.right - vscreen->monitors[i].area.left + 1, *pMaxWidth);
MIN(vscreen->monitors[i].area.right - vscreen->monitors[i].area.left + 1, *pMaxWidth);
settings->MonitorDefArray[nmonitors].height =
MIN(vscreen->monitors[i].area.bottom - vscreen->monitors[i].area.top + 1, *pMaxHeight);
MIN(vscreen->monitors[i].area.bottom - vscreen->monitors[i].area.top + 1, *pMaxHeight);
settings->MonitorDefArray[nmonitors].orig_screen = i;
#ifdef USABLE_XRANDR
if (useXRandr && rrmonitors)
{
Rotation rot, ret;
attrs = &settings->MonitorDefArray[nmonitors].attributes;
attrs->physicalWidth = rrmonitors[i].mwidth;
attrs->physicalHeight = rrmonitors[i].mheight;
ret = XRRRotations(xfc->display, i, &rot);
attrs->orientation = rot;
}
#endif
if (i == settings->MonitorIds[0])
@ -477,8 +485,10 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
out:
#ifdef USABLE_XRANDR
if (rrmonitors)
XRRFreeMonitors(rrmonitors);
#endif
return TRUE;
}