path: root/ui/tap_export_pdu.c
diff options
authorPeter Wu <peter@lekensteyn.nl>2019-01-24 12:08:57 +0100
committerAnders Broman <a.broman58@gmail.com>2019-01-25 04:53:10 +0000
commit31aba351e206b31bd82614f6402f4a1de5f4c1b3 (patch)
treee8a20d143ba119b0a3e68b211e72061f76f644ec /ui/tap_export_pdu.c
parent66345f008f944820425467c9fdb17155829f6489 (diff)
wiretap: fix memleaks with wtap_rec::opt_comment
The memory ownership of wtap_rec::opt_comment was not clear. Users of wtap were leaking memory (editcap.c). wtap readers were not sure about freeing old comments (erf) or simply ignored memleaks (pcapng). To fix this, ensure opt_comment is owned by wtap_rec and free it with wtap_rec_cleanup. The erf issue was already addressed since cf_get_packet_comment properly duplicates wth.opt_comment memory. - wtap file formats (readers): - Should allocate memory for new comments. - Should free a comment from an earlier read before writing a new one. - Users of wth: - Can only assume that opt_comment remains valid until the next read. - Can assume that wtap_dump does not modify the comment. - For random access (wtap_seek_read): should call wtap_rec_cleanup to free the comment. The test_tshark_z_expert_comment and test_text2pcap_sip_pcapng tests now pass when built with ASAN. This change was created by carefully looking at all users opt "opt_comment" and cf_get_packet_comment. Thanks to Vasil Velichkov for an initial patch which helped validating this version. Bug: 7515 Change-Id: If3152d1391e7e0d9860f04f3bc2ec41a1f6cc54b Reviewed-on: https://code.wireshark.org/review/31713 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Vasil Velichkov <vvvelichkov@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/tap_export_pdu.c')
1 files changed, 3 insertions, 0 deletions
diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c
index 5d5a11986f..b2a299b74a 100644
--- a/ui/tap_export_pdu.c
+++ b/ui/tap_export_pdu.c
@@ -54,6 +54,9 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
rec.rec_header.packet_header.pkt_encap = exp_pdu_tap_data->pkt_encap;
+ /* rec.opt_comment is not modified by wtap_dump, but if for some reason the
+ * epan_get_user_comment() or pinfo->rec->opt_comment are invalidated,
+ * copying it here does not hurt. (Can invalidation really happen?) */
if (pinfo->fd->has_user_comment) {
rec.opt_comment = g_strdup(epan_get_user_comment(edt->session, pinfo->fd));
rec.has_comment_changed = TRUE;