[vlc-commits] doc: QtGl: fix memory leak on VLCVideo

Alexandre Janniaux git at videolan.org
Thu Dec 10 13:39:36 UTC 2020


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Fri Nov 20 15:36:01 2020 +0100| [81a4d5c24b3300a6c3c8fce0935fbabc4828a313] | committer: Alexandre Janniaux

doc: QtGl: fix memory leak on VLCVideo

VLCVideo was not released, probably because it was considered like a
QObject (new VLCVideo(this)) and thus expected to be destroyed
automatically like a QObject.

Use a std::unique_ptr<> to destroy it when the parent widget is
destroyed.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=81a4d5c24b3300a6c3c8fce0935fbabc4828a313
---

 doc/libvlc/QtGL/qtvlcwidget.cpp | 4 ++--
 doc/libvlc/QtGL/qtvlcwidget.h   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/doc/libvlc/QtGL/qtvlcwidget.cpp b/doc/libvlc/QtGL/qtvlcwidget.cpp
index 3a9f4f9f04..305d989efc 100644
--- a/doc/libvlc/QtGL/qtvlcwidget.cpp
+++ b/doc/libvlc/QtGL/qtvlcwidget.cpp
@@ -201,7 +201,7 @@ QtVLCWidget::QtVLCWidget(QWidget *parent)
     };
     m_vlc = libvlc_new(sizeof(args) / sizeof(*args), args);
 
-    mVLC = new VLCVideo(this);
+    mVLC = std::make_unique<VLCVideo>(this);
 }
 
 bool QtVLCWidget::playMedia(const char* url)
@@ -223,7 +223,7 @@ bool QtVLCWidget::playMedia(const char* url)
         mVLC->isOpenGLES() ? libvlc_video_engine_gles2 : libvlc_video_engine_opengl,
         VLCVideo::setup, VLCVideo::cleanup, nullptr, VLCVideo::resizeRenderTextures, VLCVideo::swap,
         VLCVideo::make_current, VLCVideo::get_proc_address, nullptr, nullptr,
-        mVLC);
+        mVLC.get());
 
     // Play the video
     libvlc_media_player_play (m_mp);
diff --git a/doc/libvlc/QtGL/qtvlcwidget.h b/doc/libvlc/QtGL/qtvlcwidget.h
index 0d3e745c87..8e77af3a45 100644
--- a/doc/libvlc/QtGL/qtvlcwidget.h
+++ b/doc/libvlc/QtGL/qtvlcwidget.h
@@ -35,7 +35,7 @@ private:
     QOpenGLVertexArrayObject m_vao;
     QOpenGLShaderProgram *m_program;
 
-    class VLCVideo  *mVLC;
+    std::unique_ptr<class VLCVideo> mVLC;
 
     void stop();
     struct libvlc_instance_t*  m_vlc = nullptr;



More information about the vlc-commits mailing list