From 7cc0695cf7628f1163a4bdf6152447e7cb7c3fc1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 24 Oct 2024 15:51:53 -0700 Subject: [PATCH] modesetting: avoid memory leak when ms_present_check_unflip() returns FALSE Found by Oracle Parfait 13.3 static analyzer: Memory leak [memory-leak]: Memory leak of pointer event allocated with calloc(1, 16) at line 470 of hw/xfree86/drivers/modesetting/present.c in function 'ms_present_unflip'. event allocated at line 431 with calloc(1, 16) event leaks when ms_present_check_unflip(...) == 0 at line 438 and i >= config->num_crtc at line 445 Fixes: 13c7d53df ("modesetting: Implement page flipping support for Present.") Signed-off-by: Alan Coopersmith Part-of: --- hw/xfree86/drivers/modesetting/present.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c index 8956a7c57..421d70016 100644 --- a/hw/xfree86/drivers/modesetting/present.c +++ b/hw/xfree86/drivers/modesetting/present.c @@ -424,22 +424,24 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id) PixmapPtr pixmap = screen->GetScreenPixmap(screen); xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); int i; - struct ms_present_vblank_event *event; ms_present_set_screen_vrr(scrn, FALSE); - event = calloc(1, sizeof(struct ms_present_vblank_event)); - if (!event) - return; + if (ms_present_check_unflip(NULL, screen->root, pixmap, TRUE, NULL)) { + struct ms_present_vblank_event *event; - event->event_id = event_id; - event->unflip = TRUE; + event = calloc(1, sizeof(struct ms_present_vblank_event)); + if (!event) + return; - if (ms_present_check_unflip(NULL, screen->root, pixmap, TRUE, NULL) && - ms_do_pageflip(screen, pixmap, event, NULL, FALSE, - ms_present_flip_handler, ms_present_flip_abort, - "Present-unflip")) { - return; + event->event_id = event_id; + event->unflip = TRUE; + + if (ms_do_pageflip(screen, pixmap, event, NULL, FALSE, + ms_present_flip_handler, ms_present_flip_abort, + "Present-unflip")) { + return; + } } for (i = 0; i < config->num_crtc; i++) {