mirror of
https://github.com/X11Libre/xf86-video-vmware.git
synced 2026-04-14 11:04:56 +00:00
vmwgfx: Fix XVideo memory leaks
We were not properly freeing the port privates. In order to access those at CloseScreen time, don't free the adaptor pointers at XV screen init, but hold on to them until CloseScreen. Also properly free the new_adaptors pointer. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
@@ -1327,6 +1327,8 @@ drv_close_screen(CLOSE_SCREEN_ARGS_DECL)
|
||||
pScrn->LeaveVT(VT_FUNC_ARGS);
|
||||
|
||||
vmwgfx_uevent_fini(pScrn, ms);
|
||||
vmw_xv_close(pScreen);
|
||||
|
||||
pScrn->vtSema = FALSE;
|
||||
|
||||
vmwgfx_unwrap(ms, pScrn, EnterVT);
|
||||
|
||||
@@ -157,6 +157,11 @@ typedef struct _modesettingRec
|
||||
Bool xa_dri3;
|
||||
Bool dri3_available;
|
||||
#endif
|
||||
|
||||
/* Video */
|
||||
XF86VideoAdaptorPtr overlay;
|
||||
XF86VideoAdaptorPtr textured;
|
||||
|
||||
} modesettingRec, *modesettingPtr;
|
||||
|
||||
#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
|
||||
@@ -231,7 +236,9 @@ xorg_xv_init(ScreenPtr pScreen);
|
||||
XF86VideoAdaptorPtr
|
||||
vmw_video_init_adaptor(ScrnInfoPtr pScrn);
|
||||
void
|
||||
vmw_video_free_adaptor(XF86VideoAdaptorPtr adaptor, Bool free_ports);
|
||||
vmw_video_free_adaptor(XF86VideoAdaptorPtr adaptor);
|
||||
void
|
||||
vmw_xv_close(ScreenPtr pScreen);
|
||||
|
||||
void
|
||||
vmw_ctrl_ext_init(ScrnInfoPtr pScrn);
|
||||
|
||||
@@ -258,15 +258,12 @@ vmwgfx_overlay_port_create(int drm_fd, ScreenPtr pScreen)
|
||||
}
|
||||
|
||||
void
|
||||
vmw_video_free_adaptor(XF86VideoAdaptorPtr adaptor, Bool free_ports)
|
||||
vmw_video_free_adaptor(XF86VideoAdaptorPtr adaptor)
|
||||
{
|
||||
if (free_ports) {
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for(i=0; i<adaptor->nPorts; ++i) {
|
||||
free(adaptor->pPortPrivates[i].ptr);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < adaptor->nPorts; ++i)
|
||||
free(adaptor->pPortPrivates[i].ptr);
|
||||
|
||||
free(adaptor->pPortPrivates);
|
||||
xf86XVFreeVideoAdaptorRec(adaptor);
|
||||
|
||||
@@ -904,15 +904,12 @@ port_priv_create(struct xa_tracker *xat, struct xa_context *r,
|
||||
}
|
||||
|
||||
static void
|
||||
vmwgfx_free_textured_adaptor(XF86VideoAdaptorPtr adaptor, Bool free_ports)
|
||||
vmwgfx_free_textured_adaptor(XF86VideoAdaptorPtr adaptor)
|
||||
{
|
||||
if (free_ports) {
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for(i=0; i<adaptor->nPorts; ++i) {
|
||||
free(adaptor->pPortPrivates[i].ptr);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < adaptor->nPorts; ++i)
|
||||
free(adaptor->pPortPrivates[i].ptr);
|
||||
|
||||
free(adaptor->pAttributes);
|
||||
free(adaptor->pPortPrivates);
|
||||
@@ -986,6 +983,23 @@ xorg_setup_textured_adapter(ScreenPtr pScreen)
|
||||
return adapt;
|
||||
}
|
||||
|
||||
void
|
||||
vmw_xv_close(ScreenPtr pScreen)
|
||||
{
|
||||
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
|
||||
if (ms->overlay) {
|
||||
vmw_video_free_adaptor(ms->overlay);
|
||||
ms->overlay = NULL;
|
||||
}
|
||||
|
||||
if (ms->textured) {
|
||||
vmwgfx_free_textured_adaptor(ms->textured);
|
||||
ms->textured = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xorg_xv_init(ScreenPtr pScreen)
|
||||
{
|
||||
@@ -1025,17 +1039,19 @@ xorg_xv_init(ScreenPtr pScreen)
|
||||
adaptors[num_adaptors++] = overlay_adaptor;
|
||||
|
||||
if (num_adaptors) {
|
||||
Bool ret;
|
||||
ret = xf86XVScreenInit(pScreen, adaptors, num_adaptors);
|
||||
if (textured_adapter)
|
||||
vmwgfx_free_textured_adaptor(textured_adapter, !ret);
|
||||
if (overlay_adaptor)
|
||||
vmw_video_free_adaptor(overlay_adaptor, !ret);
|
||||
if (!ret)
|
||||
if (xf86XVScreenInit(pScreen, adaptors, num_adaptors)) {
|
||||
ms->overlay = overlay_adaptor;
|
||||
ms->textured = textured_adapter;
|
||||
} else {
|
||||
ms->overlay = NULL;
|
||||
ms->textured = NULL;
|
||||
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
||||
"Failed to initialize Xv.\n");
|
||||
}
|
||||
} else {
|
||||
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
|
||||
"Disabling Xv because no adaptors could be initialized.\n");
|
||||
}
|
||||
|
||||
free(new_adaptors);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user