CddaSongLoader: Fix some leaks

This commit is contained in:
Jonas Kvinge
2025-06-09 02:27:11 +02:00
parent fba4f84fb6
commit a0ec244008

View File

@@ -163,9 +163,9 @@ void CddaSongLoader::LoadSongs() {
GstMessage *msg = nullptr; GstMessage *msg = nullptr;
GstMessage *msg_toc = nullptr; GstMessage *msg_toc = nullptr;
GstMessage *msg_tag = nullptr; GstMessage *msg_tag = nullptr;
while ((msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline), GST_SECOND, static_cast<GstMessageType>(GST_MESSAGE_TOC | GST_MESSAGE_TAG)))) { while ((!msg_toc || !msg_tag) && (msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline), GST_SECOND * 5, static_cast<GstMessageType>(GST_MESSAGE_TOC | GST_MESSAGE_TAG)))) {
if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TOC) { if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TOC) {
if (msg_toc) gst_message_unref(msg_toc); // Shouldn't happen, but just in case if (msg_toc) gst_message_unref(msg_toc);
msg_toc = msg; msg_toc = msg;
} }
else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) { else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) {
@@ -190,6 +190,7 @@ void CddaSongLoader::LoadSongs() {
songs[i++].set_length_nanosec(duration); songs[i++].set_length_nanosec(duration);
} }
} }
gst_toc_unref(toc);
} }
gst_message_unref(msg_toc); gst_message_unref(msg_toc);
} }
@@ -200,18 +201,20 @@ void CddaSongLoader::LoadSongs() {
if (msg_tag) { if (msg_tag) {
GstTagList *tags = nullptr; GstTagList *tags = nullptr;
gst_message_parse_tag(msg_tag, &tags); gst_message_parse_tag(msg_tag, &tags);
char *string_mb = nullptr; if (tags) {
if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID, &string_mb)) { char *string_mb = nullptr;
QString musicbrainz_discid = QString::fromUtf8(string_mb); if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID, &string_mb)) {
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid; QString musicbrainz_discid = QString::fromUtf8(string_mb);
qLog(Info) << "MusicBrainz Disc ID: " << musicbrainz_discid;
MusicBrainzClient *musicbrainz_client = new MusicBrainzClient(network_); MusicBrainzClient *musicbrainz_client = new MusicBrainzClient(network_);
QObject::connect(musicbrainz_client, &MusicBrainzClient::DiscIdFinished, this, &CddaSongLoader::AudioCDTagsLoaded); QObject::connect(musicbrainz_client, &MusicBrainzClient::DiscIdFinished, this, &CddaSongLoader::AudioCDTagsLoaded);
musicbrainz_client->StartDiscIdRequest(musicbrainz_discid); musicbrainz_client->StartDiscIdRequest(musicbrainz_discid);
g_free(string_mb); g_free(string_mb);
gst_message_unref(msg_tag); }
gst_tag_list_unref(tags); gst_tag_list_unref(tags);
} }
gst_message_unref(msg_tag);
} }
#endif #endif