diff --git a/src/platforms/gbm-kms/server/gbm_display_allocator.cpp b/src/platforms/gbm-kms/server/gbm_display_allocator.cpp index 0afdbc8bc5..650a1764e7 100644 --- a/src/platforms/gbm-kms/server/gbm_display_allocator.cpp +++ b/src/platforms/gbm-kms/server/gbm_display_allocator.cpp @@ -58,7 +58,7 @@ class GBMBoFramebuffer : public mg::FBHandle return std::make_unique(std::move(bo), *cached_fb); } - auto fb_id = new std::shared_ptr{ + auto fb_id = std::shared_ptr{ new uint32_t{0}, [drm_fd](uint32_t* fb_id) { @@ -79,13 +79,15 @@ class GBMBoFramebuffer : public mg::FBHandle /* Create a KMS FB object with the gbm_bo attached to it. */ auto ret = drmModeAddFB2(drm_fd, width, height, format, - handles, strides, offsets, fb_id->get(), 0); + handles, strides, offsets, fb_id.get(), 0); if (ret) return nullptr; - gbm_bo_set_user_data(bo.get(), fb_id, [](gbm_bo*, void* fb_ptr) { delete static_cast*>(fb_ptr); }); + // It is weird allocating a smart pointer on the heap, but we delete it + // via gbm_bo_set_user_data()'s destroy_user_data parameter. + gbm_bo_set_user_data(bo.get(), new std::shared_ptr(fb_id), [](gbm_bo*, void* fb_ptr) { delete static_cast*>(fb_ptr); }); - return std::make_unique(std::move(bo), *fb_id); + return std::make_unique(std::move(bo), std::move(fb_id)); } operator uint32_t() const override