diff options
author | Evan Huus <eapache@gmail.com> | 2021-09-15 12:09:18 -0400 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-09-16 07:12:20 +0000 |
commit | e4b8a5851384f3cac5bb8cefa9d7f668f907d15d (patch) | |
tree | 49e5677de61f4c15f4123847f5b13f9a132192db /epan/proto.c | |
parent | f4aa108913db786e8dc4c2333849c8c07afebb2c (diff) |
ptvcursor: add explicit memory scope
I was hoping to avoid this, since the ptvcursor should already be
implicitly scoped to the tree it is working on. But there are a bunch of
call sites where the passed tree can be NULL (?) and a few places where
the tree is explicitly set/reset after creation, so requiring an
explicit scope is safer.
Avoids global memory pools in favour of ones the compiler can verify.
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/epan/proto.c b/epan/proto.c index 31eb6b8f8f..5129e78b62 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -62,6 +62,7 @@ typedef struct __subtree_lvl { } subtree_lvl; struct ptvcursor { + wmem_allocator_t *scope; subtree_lvl *pushed_tree; guint8 pushed_tree_index; guint8 pushed_tree_max; @@ -1119,7 +1120,7 @@ ptvcursor_new_subtree_levels(ptvcursor_t *ptvc) DISSECTOR_ASSERT(ptvc->pushed_tree_max <= SUBTREE_MAX_LEVELS-SUBTREE_ONCE_ALLOCATION_NUMBER); ptvc->pushed_tree_max += SUBTREE_ONCE_ALLOCATION_NUMBER; - pushed_tree = (subtree_lvl *)wmem_realloc(wmem_packet_scope(), (void *)ptvc->pushed_tree, sizeof(subtree_lvl) * ptvc->pushed_tree_max); + pushed_tree = (subtree_lvl *)wmem_realloc(ptvc->scope, (void *)ptvc->pushed_tree, sizeof(subtree_lvl) * ptvc->pushed_tree_max); DISSECTOR_ASSERT(pushed_tree != NULL); ptvc->pushed_tree = pushed_tree; } @@ -1136,11 +1137,12 @@ ptvcursor_free_subtree_levels(ptvcursor_t *ptvc) /* Allocates an initializes a ptvcursor_t with 3 variables: * proto_tree, tvbuff, and offset. */ ptvcursor_t * -ptvcursor_new(proto_tree *tree, tvbuff_t *tvb, gint offset) +ptvcursor_new(wmem_allocator_t *scope, proto_tree *tree, tvbuff_t *tvb, gint offset) { ptvcursor_t *ptvc; - ptvc = wmem_new(wmem_packet_scope(), ptvcursor_t); + ptvc = wmem_new(scope, ptvcursor_t); + ptvc->scope = scope; ptvc->tree = tree; ptvc->tvb = tvb; ptvc->offset = offset; |