[PATCH 4/8] Simplify drmmode_set_mode_major() and avoid leaking memory.

Michel Dänzer michel at daenzer.net
Tue Nov 10 23:16:02 PST 2015


From: Tom St Denis <tom.stdenis at amd.com>

The function would leak the memory allocated for output_ids.  This
patch addresses that as well as simplifies the logic somewhat.

Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
(ported from amdgpu commit 460560502a1bdf26d06f3c30df46fa9f28ffb9e5)

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/drmmode_display.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 3a3f407..561b55e 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -626,7 +626,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 	int saved_x, saved_y;
 	Rotation saved_rotation;
 	DisplayModeRec saved_mode;
-	uint32_t *output_ids;
+	uint32_t *output_ids = NULL;
 	int output_count = 0;
 	Bool ret = TRUE;
 	int i;
@@ -672,15 +672,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		crtc->y = y;
 		crtc->rotation = rotation;
 		crtc->transformPresent = FALSE;
-	}
 
-	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
-	if (!output_ids) {
-		ret = FALSE;
-		goto done;
-	}
+		output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+		if (!output_ids) {
+			ret = FALSE;
+			goto done;
+		}
 
-	if (mode) {
 		ScreenPtr pScreen = pScrn->pScreen;
 
 		for (i = 0; i < xf86_config->num_output; i++) {
@@ -792,6 +790,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		xf86_reload_cursors(pScrn->pScreen);
 
 done:
+	free(output_ids);
 	if (!ret) {
 		crtc->x = saved_x;
 		crtc->y = saved_y;
-- 
2.6.2



More information about the xorg-driver-ati mailing list