From 73db35c53c71759b3ea4e864db64d1fb57094a1c Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 5 Aug 2019 12:09:29 +0200 Subject: [PATCH] kms: Fix meta_kms_crtc_read_state gamma table memory leak Before this commit meta_kms_crtc_read_state was overwriting the entire MetaKmsCrtcState struct stored in crtc->current_state including the gamma (sub)struct. This effectively zero-s the gamma struct each time before calling read_gamma_state, setting the pointers where the previous gamma values were stored to NULL without freeing the memory. Luckily this zero-ing also sets gamma.size to 0, causing read_gamma_state to re-alloc the arrays on each meta_kms_crtc_update_state call. But this does mean that were leaking the old gamma arrays on each meta_kms_crtc_update_state call. This commit fixes this by making meta_kms_crtc_read_state only overwrite the other values in the MetaKmsCrtcState struct and leaving the gamma sub-struct alone, this will make read_gamma_state correctly re-use the gamma tables if the gamma table size is unchanged; or re-alloc them (freeing the old ones) if the size has changed, fixing the memory leak. https://gitlab.gnome.org/GNOME/mutter/merge_requests/713 --- src/backends/native/meta-kms-crtc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backends/native/meta-kms-crtc.c b/src/backends/native/meta-kms-crtc.c index 2dd2b8da4..b07a6e7d5 100644 --- a/src/backends/native/meta-kms-crtc.c +++ b/src/backends/native/meta-kms-crtc.c @@ -110,17 +110,16 @@ meta_kms_crtc_read_state (MetaKmsCrtc *crtc, MetaKmsImplDevice *impl_device, drmModeCrtc *drm_crtc) { - crtc->current_state = (MetaKmsCrtcState) { - .rect = { - .x = drm_crtc->x, - .y = drm_crtc->y, - .width = drm_crtc->width, - .height = drm_crtc->height, - }, - .is_drm_mode_valid = drm_crtc->mode_valid, - .drm_mode = drm_crtc->mode, + crtc->current_state.rect = (MetaRectangle) { + .x = drm_crtc->x, + .y = drm_crtc->y, + .width = drm_crtc->width, + .height = drm_crtc->height, }; + crtc->current_state.is_drm_mode_valid = drm_crtc->mode_valid; + crtc->current_state.drm_mode = drm_crtc->mode; + read_gamma_state (crtc, impl_device, drm_crtc); }