summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kindestam <antonki@kth.se>2018-05-02 13:26:57 +0200
committerJan Ekström <jeebjp@gmail.com>2018-05-08 02:24:40 +0300
commita645c6b2ecf72c0e64f4d32bf14115398bf5b57f (patch)
tree4667ba6bb708d5311d33d530b451d9ef42ca33a6
parent11289d52389f83edf9358fb3b93bb1bca32dc51c (diff)
downloadmpv-a645c6b2ecf72c0e64f4d32bf14115398bf5b57f.tar.bz2
mpv-a645c6b2ecf72c0e64f4d32bf14115398bf5b57f.tar.xz
drm_atomic: Fix memory leaks in drm_atomic_create
First fix a memory leak when skipping cursor planes by inverting the check and putting everything, but the free, in the body. Then fix a missed drmModeFreePlane by simply copying the fields of the drmModePlane we are interested in and freeing the drmModePlane struct early.
-rw-r--r--video/out/drm_atomic.c67
1 files changed, 33 insertions, 34 deletions
diff --git a/video/out/drm_atomic.c b/video/out/drm_atomic.c
index e6f7cdbd7e..8e68cdb074 100644
--- a/video/out/drm_atomic.c
+++ b/video/out/drm_atomic.c
@@ -140,7 +140,6 @@ void drm_object_print_info(struct mp_log *log, struct drm_object *object)
struct drm_atomic_context *drm_atomic_create_context(struct mp_log *log, int fd, int crtc_id,
int connector_id, int osd_plane_id, int video_plane_id)
{
- drmModePlane *drmplane = NULL;
drmModePlaneRes *plane_res = NULL;
drmModeRes *res = NULL;
struct drm_object *plane = NULL;
@@ -199,48 +198,50 @@ struct drm_atomic_context *drm_atomic_create_context(struct mp_log *log, int fd,
for (unsigned int j = 0; j < plane_res->count_planes; j++) {
- drmplane = drmModeGetPlane (ctx->fd, plane_res->planes[j]);
- if (drmplane->possible_crtcs & (1 << crtc_index)) {
- plane = drm_object_create(log, ctx->fd, drmplane->plane_id,
+ drmModePlane *drmplane = drmModeGetPlane(ctx->fd, plane_res->planes[j]);
+ const uint32_t possible_crtcs = drmplane->possible_crtcs;
+ const uint32_t plane_id = drmplane->plane_id;
+ drmModeFreePlane(drmplane);
+ drmplane = NULL;
+
+ if (possible_crtcs & (1 << crtc_index)) {
+ plane = drm_object_create(log, ctx->fd, plane_id,
DRM_MODE_OBJECT_PLANE);
- if (plane) {
- if (drm_object_get_property(plane, "TYPE", &value) == -EINVAL) {
- mp_err(log, "Unable to retrieve type property from plane %d\n", j);
- goto fail;
- } else {
- if (value == DRM_PLANE_TYPE_CURSOR) // Skip cursor planes
- continue;
+ if (!plane) {
+ mp_err(log, "Failed to create Plane object from plane ID %d\n",
+ plane_id);
+ goto fail;
+ }
- layercount++;
+ if (drm_object_get_property(plane, "TYPE", &value) == -EINVAL) {
+ mp_err(log, "Unable to retrieve type property from plane %d\n", j);
+ goto fail;
+ }
- if ((!primary_id) && (value == DRM_PLANE_TYPE_PRIMARY))
- primary_id = drmplane->plane_id;
+ if (value != DRM_PLANE_TYPE_CURSOR) { // Skip cursor planes
+ layercount++;
- if ((!overlay_id) && (value == DRM_PLANE_TYPE_OVERLAY))
- overlay_id = drmplane->plane_id;
+ if ((!primary_id) && (value == DRM_PLANE_TYPE_PRIMARY))
+ primary_id = plane_id;
- if (layercount == osd_plane_id) {
- ctx->osd_plane = plane;
- continue;
- }
+ if ((!overlay_id) && (value == DRM_PLANE_TYPE_OVERLAY))
+ overlay_id = plane_id;
- if (layercount == video_plane_id) {
- ctx->video_plane = plane;
- continue;
- }
+ if (layercount == osd_plane_id) {
+ ctx->osd_plane = plane;
+ continue;
+ }
- drm_object_free(plane);
- plane = NULL;
+ if (layercount == video_plane_id) {
+ ctx->video_plane = plane;
+ continue;
}
- } else {
- mp_err(log, "Failed to create Plane object from plane ID %d\n",
- drmplane->plane_id);
- goto fail;
}
+
+ drm_object_free(plane);
+ plane = NULL;
}
- drmModeFreePlane(drmplane);
- drmplane = NULL;
}
// default OSD plane to primary if unspecified
@@ -282,8 +283,6 @@ fail:
drmModeFreeResources(res);
if (plane_res)
drmModeFreePlaneResources(plane_res);
- if (drmplane)
- drmModeFreePlane(drmplane);
if (plane)
drm_object_free(plane);
return NULL;