aboutsummaryrefslogtreecommitdiffstats
path: root/editcap.c
diff options
context:
space:
mode:
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 /editcap.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 'editcap.c')
-rw-r--r--editcap.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/editcap.c b/editcap.c
index 495ab6d1d9..c1616db61e 100644
--- a/editcap.c
+++ b/editcap.c
@@ -1945,7 +1945,8 @@ main(int argc, char *argv[])
if (comment != NULL) {
/* Copy and change rather than modify returned rec */
temp_rec = *rec;
- temp_rec.opt_comment = g_strdup(comment);
+ /* The comment is not modified by dumper, cast away. */
+ temp_rec.opt_comment = (char *)comment;
temp_rec.has_comment_changed = TRUE;
rec = &temp_rec;
} else {