diff options
author | krj <krj@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-16 09:18:17 +0000 |
---|---|---|
committer | krj <krj@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-16 09:18:17 +0000 |
commit | 57884f73caecc249944367786b31ba177c64bcf4 (patch) | |
tree | 020b3208deedee177384813e9dec6c668f86482c /epan | |
parent | 3de69a948fd23dcacc0ef3fda506b63881a47e0c (diff) |
Remove the non-thread safe usage of 'last_tvb' variable in tvb_new_subset()
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@29443 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan')
-rw-r--r-- | epan/tvbuff.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index e5ff3870f2..ac8d1c066d 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -461,22 +461,10 @@ check_offset_length(guint tvb_length, guint tvb_reported_length, gint offset, gi } } -void -tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, +static void +tvb_set_subset_no_exceptions(tvbuff_t *tvb, tvbuff_t *backing, gint backing_offset, gint backing_length, gint reported_length) { - DISSECTOR_ASSERT(tvb); - DISSECTOR_ASSERT(tvb->type == TVBUFF_SUBSET); - DISSECTOR_ASSERT(!tvb->initialized); - - if (reported_length < -1) { - THROW(ReportedBoundsError); - } - - check_offset_length(backing->length, backing->reported_length, backing_offset, backing_length, - &tvb->tvbuffs.subset.offset, - &tvb->tvbuffs.subset.length); - tvb->tvbuffs.subset.tvb = backing; tvb->length = tvb->tvbuffs.subset.length; @@ -496,24 +484,41 @@ tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, } } +void +tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, + gint backing_offset, gint backing_length, gint reported_length) +{ + DISSECTOR_ASSERT(tvb); + DISSECTOR_ASSERT(tvb->type == TVBUFF_SUBSET); + DISSECTOR_ASSERT(!tvb->initialized); + + THROW_ON(reported_length < -1, ReportedBoundsError); + + check_offset_length(backing->length, backing->reported_length, backing_offset, backing_length, + &tvb->tvbuffs.subset.offset, + &tvb->tvbuffs.subset.length); + + tvb_set_subset_no_exceptions(tvb, backing, backing_offset, backing_length, reported_length); +} tvbuff_t* tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint reported_length) { - static tvbuff_t *last_tvb=NULL; tvbuff_t *tvb; + guint subset_tvb_offset; + guint subset_tvb_length; - tvb = tvb_new(TVBUFF_SUBSET); + THROW_ON(reported_length < -1, ReportedBoundsError); - if(last_tvb){ - tvb_free(last_tvb); - } - /* remember this tvb in case we throw an exception and - * lose the pointer to it. - */ - last_tvb=tvb; + check_offset_length(backing->length, backing->reported_length, backing_offset, backing_length, + &subset_tvb_offset, + &subset_tvb_length); + + tvb = tvb_new(TVBUFF_SUBSET); + tvb->tvbuffs.subset.offset = subset_tvb_offset; + tvb->tvbuffs.subset.length = subset_tvb_length; - tvb_set_subset(tvb, backing, backing_offset, backing_length, reported_length); + tvb_set_subset_no_exceptions(tvb, backing, backing_offset, backing_length, reported_length); /* * The top-level data source of this tvbuff is the top-level @@ -521,9 +526,6 @@ tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint */ tvb->ds_tvb = backing->ds_tvb; - /* ok no exception so we dont need to remember it any longer */ - last_tvb=NULL; - return tvb; } |