Clean up resources to reduce memory leaks

This commit is contained in:
alphanu1 2020-09-11 16:59:38 +01:00 committed by GitHub
parent afc3badd72
commit d7d03a8759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 19 deletions

View File

@ -271,11 +271,15 @@ static bool x11_display_server_set_resolution(void *data,
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput); XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
XSync(dpy, False); XSync(dpy, False);
}
XRRFreeCrtcInfo(crtc); XRRFreeCrtcInfo(crtc);
XRRFreeOutputInfo(outputs); XRRFreeOutputInfo(outputs);
} }
} XRRFreeCrtcInfo(crtc);
XRRFreeOutputInfo(outputs);
XRRFreeScreenResources(resources); XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }
else if (monitor_index != 20) else if (monitor_index != 20)
@ -296,11 +300,12 @@ static bool x11_display_server_set_resolution(void *data,
XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0)); XRRSetScreenSize(dpy, window, width, height, (int) ((25.4 * width) / 96.0), (int) ((25.4 * height) / 96.0));
XRRSetCrtcConfig(dpy, res, res->crtcs[monitor_index], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput); XRRSetCrtcConfig(dpy, res, res->crtcs[monitor_index], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
XSync(dpy, False); XSync(dpy, False);
XRRFreeOutputInfo(outputs);
XRRFreeCrtcInfo(crtc); XRRFreeCrtcInfo(crtc);
} }
XRRFreeOutputInfo(outputs);
XRRFreeScreenResources(resources); XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }
return true; return true;
@ -474,6 +479,8 @@ static void x11_display_server_destroy(void *data)
dispserv_x11_t *dispserv = (dispserv_x11_t*)data; dispserv_x11_t *dispserv = (dispserv_x11_t*)data;
#ifdef HAVE_XRANDR #ifdef HAVE_XRANDR
if (crt_en)
{
int screen; int screen;
Window window; Window window;
XRRScreenResources *res = NULL; XRRScreenResources *res = NULL;
@ -484,8 +491,7 @@ static void x11_display_server_destroy(void *data)
window = RootWindow(dpy, screen); window = RootWindow(dpy, screen);
bool crt_exists = false; bool crt_exists = false;
char dmode[25] ={}; char dmode[25] ={};
if (crt_en)
{
snprintf(dmode, sizeof(dmode), "%s", "d_mo"); snprintf(dmode, sizeof(dmode), "%s", "d_mo");
crt_rrmode.name = dmode; crt_rrmode.name = dmode;
@ -566,12 +572,16 @@ static void x11_display_server_destroy(void *data)
XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput); XRRSetCrtcConfig(dpy, res, res->crtcs[i], CurrentTime, crtc->x, crtc->y, crtc->mode, crtc->rotation, crtc->outputs, crtc->noutput);
XSync(dpy, False); XSync(dpy, False);
XRRFreeCrtcInfo(crtc);
XRRFreeOutputInfo(outputs);
XRRFreeCrtcInfo(crtc);
} }
XRRFreeOutputInfo(outputs);
} }
XRRFreeScreenResources(resources); XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
XCloseDisplay(dpy);
} }
else if (g_monitor_index != 20) else if (g_monitor_index != 20)
{ {
@ -595,6 +605,11 @@ static void x11_display_server_destroy(void *data)
XRRFreeCrtcInfo(crtc); XRRFreeCrtcInfo(crtc);
} }
XRRFreeOutputInfo(outputs);
XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
XCloseDisplay(dpy);
} }
@ -621,6 +636,7 @@ static void x11_display_server_destroy(void *data)
} }
} }
XRRFreeScreenResources(resources); XRRFreeScreenResources(resources);
XRRFreeScreenResources(res);
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }