From b2feff382d4b61b2fd5c575ddc2f4ee0b2a4ed7e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Mar 2025 10:27:31 +0100 Subject: [PATCH] tst_QOpenGL: don't leak 1399341 byte(s) [...] in 1439 allocation(s) That's what asan reported for a run of this test executable. Create `ctx` on the stack instead of the heap to fix the leaks. For `fbo`, use a std::optional. After these fixes, the test still leaks 64 bytes in 2 allocations. These seem to be QOpenGLSharedResourceGuards in a QOpenGLFramebufferObject. Created QTBUG-134557 to track the issue. Amends - 68974d8e647febb80a47d9cf6ce9452f3ce4fa21 (fboHandleNulledAfterContextDestroyed()) - bb760d9514ed617ee8e7344152b3fa697b2c4171 (bufferMapRange()/bufferCreate()) - 0541516907da117c391b6c8d9820209673fcd9cd (vaoCreate()) Pick-to: 6.8 6.5 5.15 Task-number: QTBUG-134557 Change-Id: Icc318cd76b9f3ddf71bc294cb96d88485c42d7bc Reviewed-by: Laszlo Agocs (cherry picked from commit 7a1cd692e0b36acfc005332b50d7ef3e11b94e71) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/gui/qopengl/tst_qopengl.cpp | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 3f4aa8cd8f9..4cc2dc49027 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -29,6 +29,8 @@ #include +#include + Q_DECLARE_METATYPE(QImage::Format) class tst_QOpenGL : public QObject @@ -770,7 +772,7 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() window.setGeometry(0, 0, 10, 10); window.create(); - QOpenGLFramebufferObject *fbo = 0; + std::optional fbo; { QOpenGLContext ctx; @@ -781,11 +783,12 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); - fbo = new QOpenGLFramebufferObject(128, 128); + fbo.emplace(128, 128); QVERIFY(fbo->handle() != 0); } + QVERIFY(fbo); QCOMPARE(fbo->handle(), 0U); } @@ -1557,30 +1560,30 @@ void tst_QOpenGL::wglContextWrap() void tst_QOpenGL::vaoCreate() { QScopedPointer surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); QOpenGLVertexArrayObject vao; bool success = vao.create(); - if (ctx->isOpenGLES()) { - if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) + if (ctx.isOpenGLES()) { + if (ctx.format().majorVersion() >= 3 || ctx.hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) QVERIFY(success); } else { - if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) + if (ctx.format().majorVersion() >= 3 || ctx.hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) QVERIFY(success); } vao.destroy(); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::bufferCreate() { QScopedPointer surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); QOpenGLBuffer buf; @@ -1607,17 +1610,17 @@ void tst_QOpenGL::bufferCreate() buf.destroy(); QVERIFY(!buf.isCreated()); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::bufferMapRange() { QScopedPointer surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); - QOpenGLExtensions funcs(ctx); + QOpenGLExtensions funcs(&ctx); if (!funcs.hasOpenGLExtension(QOpenGLExtensions::MapBufferRange)) QSKIP("glMapBufferRange not supported"); @@ -1643,7 +1646,7 @@ void tst_QOpenGL::bufferMapRange() buf.unmap(); buf.destroy(); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::defaultQGLCurrentBuffer()