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 <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1730>
This commit is contained in:
Alan Coopersmith 2024-10-24 15:51:53 -07:00 committed by Enrico Weigelt, metux IT consult
parent 8fa1ac2b50
commit 7cc0695cf7

View File

@ -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++) {