diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2012-06-13 13:11:17 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2012-06-13 13:11:37 +0100 |
commit | e499f207c161d1b3cd75f065dc89021ff5f40b63 (patch) | |
tree | 7c9c3c98f4513a9938a826d435c92dcd4f90402f /src/sna/sna_display.c | |
parent | 49da55da518348fc6b88e09d5132dd1b1d751304 (diff) |
sna: Fix memleak from sna_crtc_find_plane()
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/sna/sna_display.c')
-rw-r--r-- | src/sna/sna_display.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index 37709eef..05d97b6c 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -957,31 +957,41 @@ static const xf86CrtcFuncsRec sna_crtc_funcs = { static uint32_t sna_crtc_find_plane(struct sna *sna, int pipe) { - drmModePlaneRes *resources; - uint32_t id = 0; + struct drm_mode_get_plane_res r; + uint32_t *planes, id = 0; int i; - resources = drmModeGetPlaneResources(sna->kgem.fd); - if (!resources) { - xf86DrvMsg(sna->scrn->scrnIndex, X_ERROR, - "failed to get plane resources: %s\n", - strerror(errno)); + VG_CLEAR(r); + r.count_planes = 0; + if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &r)) + return 0; + + if (!r.count_planes) return 0; - } - for (i = 0; id == 0 && i < resources->count_planes; i++) { - drmModePlane *p; + planes = malloc(sizeof(uint32_t)*r.count_planes); + if (planes == NULL) + return 0; + + r.plane_id_ptr = (uintptr_t)planes; + if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &r)) + r.count_planes = 0; - p = drmModeGetPlane(sna->kgem.fd, resources->planes[i]); - if (p) { - if (p->possible_crtcs & (1 << pipe)) - id = p->plane_id; + for (i = 0; i < r.count_planes; i++) { + struct drm_mode_get_plane p; - drmModeFreePlane(p); + VG_CLEAR(p); + p.plane_id = planes[i]; + p.count_format_types = 0; + if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANE, &p) == 0) { + if (p.possible_crtcs & (1 << pipe)) { + id = p.plane_id; + break; + } } } + free(planes); - free(resources); return id; } |