diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-24 12:08:57 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-01-25 04:53:10 +0000 |
commit | 31aba351e206b31bd82614f6402f4a1de5f4c1b3 (patch) | |
tree | e8a20d143ba119b0a3e68b211e72061f76f644ec /wiretap/wtap.c | |
parent | 66345f008f944820425467c9fdb17155829f6489 (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 'wiretap/wtap.c')
-rw-r--r-- | wiretap/wtap.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 693999bbce..fb77a4b23e 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -1460,6 +1460,8 @@ wtap_rec_init(wtap_rec *rec) void wtap_rec_cleanup(wtap_rec *rec) { + g_free(rec->opt_comment); + rec->opt_comment = NULL; ws_buffer_free(&rec->options_buf); } |