Fix memory ownership when using cf_get_packet_comment
cf_get_packet_comment already has one code path that returns duplicated memory. Be sure to document the requirement to free this memory and adjust Qt to avoid memory leaks. Be firm and assume that wth.opt_comment is owned by wth, so duplicate it before returning it from cf_get_packet_comment. Change-Id: I91f406296c9db5ea21b90fc2e108c37de4528527 Ping-Bug: 7515 Reviewed-on: https://code.wireshark.org/review/31712 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>
This commit is contained in:
parent
e85c8bed87
commit
66345f008f
3
file.c
3
file.c
|
@ -3962,7 +3962,8 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd)
|
|||
if (!cf_read_record_r(cf, fd, &rec, &buf))
|
||||
{ /* XXX, what we can do here? */ }
|
||||
|
||||
comment = rec.opt_comment;
|
||||
/* rec.opt_comment is owned by the record, copy it before it is gone. */
|
||||
comment = g_strdup(rec.opt_comment);
|
||||
wtap_rec_cleanup(&rec);
|
||||
ws_buffer_free(&buf);
|
||||
return comment;
|
||||
|
|
1
file.h
1
file.h
|
@ -686,6 +686,7 @@ void cf_update_section_comment(capture_file *cf, gchar *comment);
|
|||
*
|
||||
* @param cf the capture file
|
||||
* @param fd the frame_data structure for the frame
|
||||
* @returns A comment (use g_free to free) or NULL if there is none.
|
||||
*/
|
||||
char *cf_get_packet_comment(capture_file *cf, const frame_data *fd);
|
||||
|
||||
|
|
|
@ -542,7 +542,7 @@ void CaptureFilePropertiesDialog::fillDetails()
|
|||
|
||||
if (pkt_comment) {
|
||||
QString frame_comment_html = tr("<p>Frame %1: ").arg(framenum);
|
||||
QString raw_comment = pkt_comment;
|
||||
QString raw_comment = gchar_free_to_qstring(pkt_comment);
|
||||
|
||||
frame_comment_html += html_escape(raw_comment).replace('\n', "<br>");
|
||||
frame_comment_html += "</p>\n";
|
||||
|
|
|
@ -1127,10 +1127,9 @@ QString PacketList::packetComment()
|
|||
if (!fdata) return NULL;
|
||||
|
||||
pkt_comment = cf_get_packet_comment(cap_file_, fdata);
|
||||
if (!pkt_comment) return NULL;
|
||||
|
||||
return QString(pkt_comment);
|
||||
|
||||
/* XXX, g_free(pkt_comment) */
|
||||
return gchar_free_to_qstring(pkt_comment);
|
||||
}
|
||||
|
||||
void PacketList::setPacketComment(QString new_comment)
|
||||
|
|
Loading…
Reference in New Issue