From 0d23b6692f6a54cc07573abb451a919febbc1b3e Mon Sep 17 00:00:00 2001 From: John Thacker Date: Wed, 1 Mar 2023 21:06:11 -0500 Subject: [PATCH] Qt: RtpStreamDialog leak In tapReset, the select rtpstread_id is copied member by member by QList append(), so don't allocate pointers on the heap that will be leaked. (Coverity 1477952) --- ui/qt/rtp_stream_dialog.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/qt/rtp_stream_dialog.cpp b/ui/qt/rtp_stream_dialog.cpp index effde6f07c..7153e0aee6 100644 --- a/ui/qt/rtp_stream_dialog.cpp +++ b/ui/qt/rtp_stream_dialog.cpp @@ -498,13 +498,16 @@ void RtpStreamDialog::tapReset(rtpstream_tapinfo_t *tapinfo) rtp_stream_dialog->freeLastSelected(); /* Copy currently selected rtpstream_ids */ QTreeWidgetItemIterator iter(rtp_stream_dialog->ui->streamTreeWidget); + rtpstream_id_t selected_id; while (*iter) { RtpStreamTreeWidgetItem *rsti = static_cast(*iter); rtpstream_info_t *stream_info = rsti->streamInfo(); if ((*iter)->isSelected()) { - rtpstream_id_t *i = (rtpstream_id_t *)g_malloc0(sizeof(rtpstream_id_t)); - rtpstream_id_copy(&stream_info->id, i); - rtp_stream_dialog->last_selected_.append(*i); + /* QList.append() does a member by member copy, so allocate new + * addresses. rtpstream_id_copy() overwrites all struct members. + */ + rtpstream_id_copy(&stream_info->id, &selected_id); + rtp_stream_dialog->last_selected_.append(selected_id); } ++iter; }