diff --git a/epan/proto.c b/epan/proto.c index ea89ac7fcc..fec13db63d 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -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);