tap: fix remaining potential memleaks with register_tap_listener

Additionally, add an attribute to the tap function to prevent future
callers from leaking this memory.

Change-Id: Ief6af2bbc74d19153628f09d7b273e85cb2284ab
Reviewed-on: https://code.wireshark.org/review/26642
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2018-03-25 23:24:59 +02:00 committed by Anders Broman
parent 3b042a7172
commit 802223829e
5 changed files with 34 additions and 6 deletions

View File

@ -208,7 +208,7 @@ WS_DLL_PUBLIC void draw_tap_listeners(gboolean draw_all);
WS_DLL_PUBLIC GString *register_tap_listener(const char *tapname, void *tapdata,
const char *fstring, guint flags, tap_reset_cb tap_reset,
tap_packet_cb tap_packet, tap_draw_cb tap_draw);
tap_packet_cb tap_packet, tap_draw_cb tap_draw) G_GNUC_WARN_UNUSED_RESULT;
/** This function sets a new dfilter to a tap listener */
WS_DLL_PUBLIC GString *set_tap_dfilter(void *tapdata, const char *fstring);

View File

@ -28,6 +28,7 @@
#include <epan/packet.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/report_message.h>
#include "ui/gtk/graph_analysis.h"
#include "ui/gtk/dlg_utils.h"
@ -159,8 +160,15 @@ flow_graph_on_ok(GtkButton *button _U_, gpointer user_data)
if (analysis != NULL)
{
register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), graph_analysis, display_filter, sequence_analysis_get_tap_flags(analysis),
GString *error_string;
error_string = register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), graph_analysis, display_filter, sequence_analysis_get_tap_flags(analysis),
NULL, sequence_analysis_get_packet_func(analysis), NULL);
if (error_string) {
report_failure("Flow graph - tap registration failed: %s", error_string->str);
g_string_free(error_string, TRUE);
return;
}
cf_retap_packets(&cfile);
remove_tap_listener(graph_analysis);

View File

@ -13,6 +13,7 @@
#include <epan/dissectors/packet-rtp.h>
#include <wsutil/report_message.h>
#include <wsutil/utf8_entities.h>
#include <ui/qt/utils/color_utils.h>
@ -209,7 +210,14 @@ void RtpPlayerDialog::reject()
void RtpPlayerDialog::retapPackets()
{
register_tap_listener("rtp", this, NULL, 0, NULL, tapPacket, NULL);
GString *error_string;
error_string = register_tap_listener("rtp", this, NULL, 0, NULL, tapPacket, NULL);
if (error_string) {
report_failure("RTP Player - tap registration failed: %s", error_string->str);
g_string_free(error_string, TRUE);
return;
}
cap_file_.retapPackets();
remove_tap_listener(this);

View File

@ -16,6 +16,7 @@
#include "wsutil/nstime.h"
#include "wsutil/utf8_entities.h"
#include "wsutil/file_util.h"
#include <wsutil/report_message.h>
#include <ui/qt/utils/color_utils.h>
#include "progress_frame.h"
@ -421,12 +422,17 @@ void SequenceDialog::fillDiagram()
register_analysis_t* analysis = sequence_analysis_find_by_name(info_->sainfo()->name);
if (analysis != NULL)
{
GString *error_string;
const char *filter = NULL;
if (ui->displayFilterCheckBox->checkState() == Qt::Checked)
filter = cap_file_.capFile()->dfilter;
register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), info_->sainfo(), filter, sequence_analysis_get_tap_flags(analysis),
error_string = register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), info_->sainfo(), filter, sequence_analysis_get_tap_flags(analysis),
NULL, sequence_analysis_get_packet_func(analysis), NULL);
if (error_string) {
report_failure("Sequence dialog - tap registration failed: %s", error_string->str);
g_string_free(error_string, TRUE);
}
cf_retap_packets(cap_file_.capFile());
remove_tap_listener(info_->sainfo());

View File

@ -31,7 +31,8 @@
#include <ui/qt/utils/color_utils.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include "wireshark_application.h"
#include "wsutil/utf8_entities.h"
#include <wsutil/report_message.h>
#include <wsutil/utf8_entities.h>
#ifdef Q_OS_WIN
#include "wsutil/file_util.h"
@ -298,7 +299,12 @@ void WirelessTimeline::captureFileReadFinished()
void WirelessTimeline::appInitialized()
{
register_tap_listener("wlan_radio_timeline", this, NULL, TL_REQUIRES_NOTHING, tap_timeline_reset, tap_timeline_packet, NULL/*tap_draw_cb tap_draw*/);
GString *error_string;
error_string = register_tap_listener("wlan_radio_timeline", this, NULL, TL_REQUIRES_NOTHING, tap_timeline_reset, tap_timeline_packet, NULL/*tap_draw_cb tap_draw*/);
if (error_string) {
report_failure("Wireless Timeline - tap registration failed: %s", error_string->str);
g_string_free(error_string, TRUE);
}
}
void WirelessTimeline::resizeEvent(QResizeEvent*)