Creat protocol tvbuff before allocating and freeing memory.
That way, if the attempt to create the protocol tvbuff throws an exception, we won't leak the protocol representation string, as we won't even try to allocate it. Bug: 14719 Change-Id: Id2855bc97e71aa0682737d1a04486a2a01f5f1e6 Reviewed-on: https://code.wireshark.org/review/27730 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
f01ff0cb0c
commit
0f1f1d0ab8
|
@ -3545,6 +3545,7 @@ proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
|||
gint start, gint length, const char *format, ...)
|
||||
{
|
||||
proto_item *pi;
|
||||
tvbuff_t *protocol_tvb;
|
||||
va_list ap;
|
||||
header_field_info *hfinfo;
|
||||
gchar* protocol_rep;
|
||||
|
@ -3555,11 +3556,16 @@ proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
|
|||
|
||||
DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_PROTOCOL);
|
||||
|
||||
/*
|
||||
* This can throw an exception, so do it before we allocate anything.
|
||||
*/
|
||||
protocol_tvb = (start == 0 ? tvb : tvb_new_subset_length(tvb, start, length));
|
||||
|
||||
pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length);
|
||||
|
||||
va_start(ap, format);
|
||||
protocol_rep = g_strdup_vprintf(format, ap);
|
||||
proto_tree_set_protocol_tvb(PNODE_FINFO(pi), (start == 0 ? tvb : tvb_new_subset_length(tvb, start, length)), protocol_rep);
|
||||
proto_tree_set_protocol_tvb(PNODE_FINFO(pi), protocol_tvb, protocol_rep);
|
||||
g_free(protocol_rep);
|
||||
va_end(ap);
|
||||
|
||||
|
|
Loading…
Reference in New Issue