[PATCH xf86-video-amdgpu 2/4] Free memory returned by xf86GetEntityInfo

Michel Dänzer michel at daenzer.net
Thu Oct 19 16:05:34 UTC 2017


From: Michel Dänzer <michel.daenzer at amd.com>

We were leaking it.

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/amdgpu_kms.c   | 19 +++++++++++++------
 src/amdgpu_probe.c |  6 ++++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 44a99b564..7d582095b 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -116,16 +116,24 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 	AMDGPUInfoPtr info;
+	EntityInfoPtr pEnt;
 
 	if (!pScrn)
 		return;
 
 	info = AMDGPUPTR(pScrn);
-	if (info && info->fbcon_pixmap)
-		pScrn->pScreen->DestroyPixmap(info->fbcon_pixmap);
+	if (info) {
+		if (info->fbcon_pixmap)
+			pScrn->pScreen->DestroyPixmap(info->fbcon_pixmap);
 
-	pPriv = xf86GetEntityPrivate(xf86GetEntityInfo(pScrn->entityList[pScrn->numEntities - 1])->index,
-				     gAMDGPUEntityIndex);
+		pEnt = info->pEnt;
+		free(pScrn->driverPrivate);
+		pScrn->driverPrivate = NULL;
+	} else {
+		pEnt = xf86GetEntityInfo(pScrn->entityList[pScrn->numEntities - 1]);
+	}
+
+	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
 	pAMDGPUEnt = pPriv->ptr;
 	if (pAMDGPUEnt->fd > 0) {
 		DevUnion *pPriv;
@@ -143,8 +151,7 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 		}
 	}
 
-	free(pScrn->driverPrivate);
-	pScrn->driverPrivate = NULL;
+	free(pEnt);
 }
 
 static void *amdgpuShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset,
diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index e446539d6..021706088 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -177,7 +177,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 {
 	ScrnInfoPtr pScrn = NULL;
 	char *busid;
-	EntityInfoPtr pEnt;
+	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 
@@ -256,6 +256,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
+	free(pEnt);
 	free(busid);
 	return FALSE;
 }
@@ -294,7 +295,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 	ScrnInfoPtr pScrn;
 	int scr_flags = 0;
 	char *busid;
-	EntityInfoPtr pEnt;
+	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 
@@ -379,6 +380,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
+	free(pEnt);
 	free(busid);
 	return FALSE;
 }
-- 
2.14.2



More information about the amd-gfx mailing list