[vlc-commits] qt: audiodevicemodel: fix memory leak
Alexandre Janniaux
git at videolan.org
Thu Feb 13 12:15:18 CET 2020
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Tue Jan 28 17:35:22 2020 +0100| [4519b053fddd0fbd8a9b633e2bb3cfe307965ed0] | committer: Jean-Baptiste Kempf
qt: audiodevicemodel: fix memory leak
Simplify the release of devices list while ensuring the array are
correctly released even when there is no devices in the list.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4519b053fddd0fbd8a9b633e2bb3cfe307965ed0
---
modules/gui/qt/util/audio_device_model.cpp | 14 ++++++--------
modules/gui/qt/util/audio_device_model.hpp | 8 ++++----
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/modules/gui/qt/util/audio_device_model.cpp b/modules/gui/qt/util/audio_device_model.cpp
index 272e429128..8e59c32f9c 100644
--- a/modules/gui/qt/util/audio_device_model.cpp
+++ b/modules/gui/qt/util/audio_device_model.cpp
@@ -52,17 +52,15 @@ AudioDeviceModel::AudioDeviceModel(vlc_player_t *player, QObject *parent)
AudioDeviceModel::~AudioDeviceModel()
{
- if (m_inputs > 0)
+ for (int i=0; i<m_inputs; i++)
{
- for (int i=0; i<m_inputs; i++){
- free(m_ids[i]);
- free(m_names[i]);
- }
-
- free(m_ids);
- free(m_names);
+ free(m_ids[i]);
+ free(m_names[i]);
}
+ free(m_ids);
+ free(m_names);
+
vlc_player_locker locker{m_player};
vlc_player_aout_RemoveListener(m_player, m_player_aout_listener);
diff --git a/modules/gui/qt/util/audio_device_model.hpp b/modules/gui/qt/util/audio_device_model.hpp
index 3b5fb6d419..b8e040562b 100644
--- a/modules/gui/qt/util/audio_device_model.hpp
+++ b/modules/gui/qt/util/audio_device_model.hpp
@@ -46,15 +46,15 @@ public:
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
-
+
void updateCurrent(QString current);
-
+
QHash<int, QByteArray> roleNames() const override;
private:
int m_inputs = 0;
- char **m_names;
- char **m_ids;
+ char **m_names = nullptr;
+ char **m_ids = nullptr;
QString m_current;
vlc_player_aout_listener_id* m_player_aout_listener = nullptr;
audio_output_t* m_aout = nullptr;
More information about the vlc-commits
mailing list