aboutsummaryrefslogtreecommitdiffhomepage
path: root/video
diff options
context:
space:
mode:
authorGravatar Anton Kindestam <antonki@kth.se>2018-06-02 12:53:47 +0200
committerGravatar Jan Ekström <jeebjp@gmail.com>2018-07-09 02:17:47 +0300
commit1298b9d201fc61cfffc6f82d78ae27fc294655b7 (patch)
treefa5a1b0c8294721f48062c367ff9e9ea9bf36046 /video
parent1a893e8257236b3beca80c0f53d7b6b972fede5c (diff)
context_drm_egl: Fix some memory leaks on error exit
Fix some memory leaks on error exit in crtc_setup_atomic and crtc_release_atomic.
Diffstat (limited to 'video')
-rw-r--r--video/out/opengl/context_drm_egl.c129
1 files changed, 66 insertions, 63 deletions
diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c
index 1ba7f5dd05..c101a5b809 100644
--- a/video/out/opengl/context_drm_egl.c
+++ b/video/out/opengl/context_drm_egl.c
@@ -253,52 +253,54 @@ static bool crtc_setup_atomic(struct ra_ctx *ctx)
struct drm_atomic_context *atomic_ctx = p->kms->atomic_context;
drmModeAtomicReqPtr request = drmModeAtomicAlloc();
- if (request) {
- if (drm_object_set_property(request, atomic_ctx->connector, "CRTC_ID", p->kms->crtc_id) < 0) {
- MP_ERR(ctx->vo, "Could not set CRTC_ID on connector\n");
- return false;
- }
-
- uint32_t blob_id;
- if (drmModeCreatePropertyBlob(p->kms->fd, &p->kms->mode, sizeof(drmModeModeInfo),
- &blob_id) != 0) {
- MP_ERR(ctx->vo, "Failed to create DRM mode blob\n");
- return false;
- }
- if (drm_object_set_property(request, atomic_ctx->crtc, "MODE_ID", blob_id) < 0) {
- MP_ERR(ctx->vo, "Could not set MODE_ID on crtc\n");
- return false;
- }
- if (drm_object_set_property(request, atomic_ctx->crtc, "ACTIVE", 1) < 0) {
- MP_ERR(ctx->vo, "Could not set ACTIVE on crtc\n");
- return false;
- }
-
- drm_object_set_property(request, atomic_ctx->osd_plane, "FB_ID", p->fb->id);
- drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_ID", p->kms->crtc_id);
- drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_X", 0);
- drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_Y", 0);
- drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_W", p->osd_size.width << 16);
- drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_H", p->osd_size.height << 16);
- drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_X", 0);
- drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_Y", 0);
- drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_W", p->kms->mode.hdisplay);
- drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_H", p->kms->mode.vdisplay);
-
- int ret = drmModeAtomicCommit(p->kms->fd, request, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
- if (ret) {
- MP_ERR(ctx->vo, "Failed to commit ModeSetting atomic request (%d)\n", ret);
- drmModeAtomicFree(request);
- return false;
- }
-
- drmModeAtomicFree(request);
-
- return ret == 0;
- } else {
+ if (!request) {
MP_ERR(ctx->vo, "Failed to allocate drm atomic request\n");
+ return false;
}
+ if (drm_object_set_property(request, atomic_ctx->connector, "CRTC_ID", p->kms->crtc_id) < 0) {
+ MP_ERR(ctx->vo, "Could not set CRTC_ID on connector\n");
+ return false;
+ }
+
+ uint32_t blob_id = 0;
+ if (drmModeCreatePropertyBlob(p->kms->fd, &p->kms->mode, sizeof(drmModeModeInfo),
+ &blob_id) != 0) {
+ MP_ERR(ctx->vo, "Failed to create DRM mode blob\n");
+ blob_id = 0;
+ goto err;
+ }
+ if (drm_object_set_property(request, atomic_ctx->crtc, "MODE_ID", blob_id) < 0) {
+ MP_ERR(ctx->vo, "Could not set MODE_ID on crtc\n");
+ goto err;
+ }
+ if (drm_object_set_property(request, atomic_ctx->crtc, "ACTIVE", 1) < 0) {
+ MP_ERR(ctx->vo, "Could not set ACTIVE on crtc\n");
+ goto err;
+ }
+
+ drm_object_set_property(request, atomic_ctx->osd_plane, "FB_ID", p->fb->id);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_ID", p->kms->crtc_id);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_X", 0);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_Y", 0);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_W", p->osd_size.width << 16);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "SRC_H", p->osd_size.height << 16);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_X", 0);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_Y", 0);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_W", p->kms->mode.hdisplay);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "CRTC_H", p->kms->mode.vdisplay);
+
+ int ret = drmModeAtomicCommit(p->kms->fd, request, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
+ if (ret)
+ MP_ERR(ctx->vo, "Failed to commit ModeSetting atomic request (%d)\n", ret);
+
+ drmModeAtomicFree(request);
+ return ret == 0;
+
+ err:
+ if (blob_id)
+ drmModeDestroyPropertyBlob(p->kms->fd, blob_id);
+ drmModeAtomicFree(request);
return false;
}
@@ -308,31 +310,32 @@ static bool crtc_release_atomic(struct ra_ctx *ctx)
struct drm_atomic_context *atomic_ctx = p->kms->atomic_context;
drmModeAtomicReqPtr request = drmModeAtomicAlloc();
- if (request) {
- drm_object_set_property(request, atomic_ctx->connector, "CRTC_ID", p->old_crtc->crtc_id);
-
- uint32_t blob_id;
- if (drmModeCreatePropertyBlob(p->kms->fd, &p->old_crtc->mode, sizeof(drmModeModeInfo),
- &blob_id) != 0) {
- MP_ERR(ctx->vo, "Failed to create DRM mode blob\n");
- return false;
- }
- drm_object_set_property(request, atomic_ctx->crtc, "MODE_ID", blob_id);
- drm_object_set_property(request, atomic_ctx->crtc, "ACTIVE", 1);
- drm_object_set_property(request, atomic_ctx->osd_plane, "FB_ID", p->old_crtc->buffer_id);
+ if (!request) {
+ MP_ERR(ctx->vo, "Failed to allocate drm atomic request\n");
+ return false;
+ }
+ drm_object_set_property(request, atomic_ctx->connector, "CRTC_ID", p->old_crtc->crtc_id);
- int ret = drmModeAtomicCommit(p->kms->fd, request, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
+ uint32_t blob_id;
+ if (drmModeCreatePropertyBlob(p->kms->fd, &p->old_crtc->mode, sizeof(drmModeModeInfo),
+ &blob_id) != 0) {
+ MP_ERR(ctx->vo, "Failed to create DRM mode blob\n");
+ goto err;
+ }
+ drm_object_set_property(request, atomic_ctx->crtc, "MODE_ID", blob_id);
+ drm_object_set_property(request, atomic_ctx->crtc, "ACTIVE", 1);
+ drm_object_set_property(request, atomic_ctx->osd_plane, "FB_ID", p->old_crtc->buffer_id);
- if (ret)
- MP_WARN(ctx->vo, "Failed to commit ModeSetting atomic request (%d)\n", ret);
+ int ret = drmModeAtomicCommit(p->kms->fd, request, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
- drmModeAtomicFree(request);
+ if (ret)
+ MP_WARN(ctx->vo, "Failed to commit ModeSetting atomic request (%d)\n", ret);
- return ret == 0;
- } else {
- MP_ERR(ctx->vo, "Failed to allocate drm atomic request\n");
- }
+ drmModeAtomicFree(request);
+ return ret == 0;
+ err:
+ drmModeAtomicFree(request);
return false;
}