[vlc-devel] [PATCH 1/2] doc: QtGl: fix memory leak on VLCVideo
Alexandre Janniaux
ajanni at videolabs.io
Fri Nov 20 15:47:06 CET 2020
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.
---
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;
--
2.29.2
More information about the vlc-devel
mailing list