aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2021-08-27 14:56:00 -0400
committerAndersBroman <a.broman58@gmail.com>2021-09-01 03:54:52 +0000
commitcdfab0d6e991df2fd3591ef896ba36937a8d4dfc (patch)
tree180c49932c562eb644c5f24d6c8d8cbf13a936e3 /epan/tvbuff.c
parent61e66c37abb1b7f59726e4407ac8dd53e6b75cac (diff)
tvbuff: convert helper methods to pinfo->pool
A few of them just needed scratch memory, so allocate and free it manually after doing any exception-raising checks. A few others were returning memory, and needed conversion to accept a wmem scope argument.
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 7a1d7956b9..c44bca3338 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1661,8 +1661,8 @@ GByteArray*
tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
const guint encoding, GByteArray *bytes, gint *endoff)
{
- const gchar *ptr = (gchar*) tvb_get_raw_string(wmem_packet_scope(), tvb, offset, length);
- const gchar *begin = ptr;
+ gchar *ptr;
+ const gchar *begin;
const gchar *end = NULL;
GByteArray *retval = NULL;
@@ -1670,6 +1670,9 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
validate_single_byte_ascii_encoding(encoding);
+ ptr = (gchar*) tvb_get_raw_string(NULL, tvb, offset, length);
+ begin = ptr;
+
if (endoff) *endoff = 0;
while (*begin == ' ') begin++;
@@ -1684,6 +1687,8 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
}
}
+ wmem_free(NULL, ptr);
+
return retval;
}
@@ -1706,8 +1711,8 @@ nstime_t*
tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
const guint encoding, nstime_t *ns, gint *endoff)
{
- const gchar *begin = (gchar*) tvb_get_raw_string(wmem_packet_scope(), tvb, offset, length);
- const gchar *ptr = begin;
+ gchar *begin;
+ const gchar *ptr;
const gchar *end = NULL;
struct tm tm;
nstime_t* retval = NULL;
@@ -1723,6 +1728,9 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
DISSECTOR_ASSERT(ns);
+ begin = (gchar*) tvb_get_raw_string(NULL, tvb, offset, length);
+ ptr = begin;
+
memset(&tm, 0, sizeof(tm));
tm.tm_isdst = -1;
ns->secs = 0;
@@ -1916,6 +1924,8 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
*endoff = (gint)(offset + (end - begin));
}
+ wmem_free(NULL, begin);
+
return retval;
}
@@ -2455,7 +2465,7 @@ tvb_memeql(tvbuff_t *tvb, const gint offset, const guint8 *str, size_t size)
* wmem packet_scoped so call must be in that scope.
*/
gchar *
-tvb_format_text(tvbuff_t *tvb, const gint offset, const gint size)
+tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint size)
{
const guint8 *ptr;
gint len;
@@ -2463,7 +2473,7 @@ tvb_format_text(tvbuff_t *tvb, const gint offset, const gint size)
len = (size > 0) ? size : 0;
ptr = ensure_contiguous(tvb, offset, size);
- return format_text(wmem_packet_scope(), ptr, len);
+ return format_text(scope, ptr, len);
}
/*
@@ -2487,7 +2497,7 @@ tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offse
* so call must be in that scope.
*/
gchar *
-tvb_format_stringzpad(tvbuff_t *tvb, const gint offset, const gint size)
+tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint size)
{
const guint8 *ptr, *p;
gint len;
@@ -2498,7 +2508,7 @@ tvb_format_stringzpad(tvbuff_t *tvb, const gint offset, const gint size)
ptr = ensure_contiguous(tvb, offset, size);
for (p = ptr, stringlen = 0; stringlen < len && *p != '\0'; p++, stringlen++)
;
- return format_text(wmem_packet_scope(), ptr, stringlen);
+ return format_text(scope, ptr, stringlen);
}
/*
@@ -4305,21 +4315,21 @@ tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gi
/* XXXX Fix me - needs odd indicator added */
const gchar *
-tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first)
+tvb_bcd_dig_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first)
{
if (!dgt)
dgt = &Dgt0_9_bcd;
- return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first, FALSE, FALSE);
+ return tvb_get_bcd_string(scope, tvb, offset, len, dgt, skip_first, FALSE, FALSE);
}
const gchar *
-tvb_bcd_dig_to_wmem_packet_str_be(tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first)
+tvb_bcd_dig_to_str_be(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first)
{
if (!dgt)
dgt = &Dgt0_9_bcd;
- return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first, FALSE, TRUE);
+ return tvb_get_bcd_string(scope, tvb, offset, len, dgt, skip_first, FALSE, TRUE);
}
/*