mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
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.
This commit is contained in:
committed by
Jan Ekström
parent
11289d5238
commit
a645c6b2ec
@@ -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,
|
||||
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;
|
||||
|
||||
layercount++;
|
||||
|
||||
if ((!primary_id) && (value == DRM_PLANE_TYPE_PRIMARY))
|
||||
primary_id = drmplane->plane_id;
|
||||
|
||||
if ((!overlay_id) && (value == DRM_PLANE_TYPE_OVERLAY))
|
||||
overlay_id = drmplane->plane_id;
|
||||
|
||||
if (layercount == osd_plane_id) {
|
||||
ctx->osd_plane = plane;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layercount == video_plane_id) {
|
||||
ctx->video_plane = plane;
|
||||
continue;
|
||||
}
|
||||
|
||||
drm_object_free(plane);
|
||||
plane = NULL;
|
||||
}
|
||||
} else {
|
||||
mp_err(log, "Failed to create Plane object from plane ID %d\n",
|
||||
drmplane->plane_id);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
mp_err(log, "Failed to create Plane object from plane ID %d\n",
|
||||
plane_id);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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 (value != DRM_PLANE_TYPE_CURSOR) { // Skip cursor planes
|
||||
layercount++;
|
||||
|
||||
if ((!primary_id) && (value == DRM_PLANE_TYPE_PRIMARY))
|
||||
primary_id = plane_id;
|
||||
|
||||
if ((!overlay_id) && (value == DRM_PLANE_TYPE_OVERLAY))
|
||||
overlay_id = plane_id;
|
||||
|
||||
if (layercount == osd_plane_id) {
|
||||
ctx->osd_plane = plane;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layercount == video_plane_id) {
|
||||
ctx->video_plane = plane;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
drm_object_free(plane);
|
||||
plane = 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;
|
||||
|
||||
Reference in New Issue
Block a user