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
This commit is contained in:
Hans de Goede 2019-08-05 12:09:29 +02:00 committed by Jonas Ådahl
parent 76445bcb97
commit 73db35c53c

View File

@ -110,17 +110,16 @@ meta_kms_crtc_read_state (MetaKmsCrtc *crtc,
MetaKmsImplDevice *impl_device,
drmModeCrtc *drm_crtc)
{
crtc->current_state = (MetaKmsCrtcState) {
.rect = {
crtc->current_state.rect = (MetaRectangle) {
.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.is_drm_mode_valid = drm_crtc->mode_valid;
crtc->current_state.drm_mode = drm_crtc->mode;
read_gamma_state (crtc, impl_device, drm_crtc);
}