aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmann <mmann@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-25 00:39:17 +0000
committermmann <mmann@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-25 00:39:17 +0000
commitee55f0a9cfa0e38f2b8565b71c095f53adaede87 (patch)
treec486a109151a4d15818d59e77c8e0c869bd0e1b4
parentdbcb1724f0f6c689f41c00cd67ede068cad2286e (diff)
cleanup some unnecessary g_malloc calls
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@44662 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r--epan/dissectors/packet-tpncp.c9
-rw-r--r--epan/dissectors/packet-wsp.c2
-rw-r--r--epan/dissectors/packet-x11.c53
-rw-r--r--epan/dissectors/packet-xdmcp.c24
4 files changed, 14 insertions, 74 deletions
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c
index 8bbe430f1a..5209bae9b6 100644
--- a/epan/dissectors/packet-tpncp.c
+++ b/epan/dissectors/packet-tpncp.c
@@ -140,7 +140,6 @@ static void dissect_tpncp_data(gint data_id, tvbuff_t *tvb, proto_item *item,
guint16 g_ushort;
gint8 g_char;
guint8 g_uchar;
- gchar *g_str = NULL;
gint g_str_len, counter, bitshift, bitmask;
tpncp_data_field_info *current_tpncp_data_field_info = NULL;
@@ -153,13 +152,9 @@ static void dissect_tpncp_data(gint data_id, tvbuff_t *tvb, proto_item *item,
case 5: case 6: case 7: case 8:
if ((g_str_len = current_tpncp_data_field_info->tpncp_data_field_array_dim)) { /* add char array */
g_str_len = MIN(g_str_len, tvb_length_remaining(tvb, *offset));
- g_str = g_malloc(g_str_len);
- tvb_memcpy(tvb, g_str, *offset, g_str_len);
- g_str[g_str_len-1] = '\0';
- proto_tree_add_string(ltree, current_tpncp_data_field_info->tpncp_data_field_descr,
- tvb, *offset, g_str_len, g_str);
+ proto_tree_add_item(ltree, current_tpncp_data_field_info->tpncp_data_field_descr,
+ tvb, *offset, g_str_len, ENC_NA|ENC_ASCII);
(*offset) += g_str_len;
- g_free(g_str);
}
else { /* add single char */
g_uchar = tvb_get_guint8(tvb, *offset);
diff --git a/epan/dissectors/packet-wsp.c b/epan/dissectors/packet-wsp.c
index a61924c43e..919a8b4b42 100644
--- a/epan/dissectors/packet-wsp.c
+++ b/epan/dissectors/packet-wsp.c
@@ -5844,7 +5844,7 @@ add_post_variable (proto_tree *tree, tvbuff_t *tvb, guint variableStart, guint v
if (valueEnd < valueStart)
{
- valueBuffer = g_malloc (1);
+ valueBuffer = ep_alloc (1);
valueBuffer[0] = 0;
valueEnd = valueStart;
}
diff --git a/epan/dissectors/packet-x11.c b/epan/dissectors/packet-x11.c
index 500c4bf7d5..b88d0a9d65 100644
--- a/epan/dissectors/packet-x11.c
+++ b/epan/dissectors/packet-x11.c
@@ -2078,24 +2078,10 @@ static void listOfSegment(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
}
}
-/* XXX - the protocol tree code should handle non-printable characters.
- Note that "non-printable characters" may depend on your locale.... */
-static void stringCopy(char *dest, const char *source, int length)
-{
- guchar c;
- while(length--) {
- c = *source++;
- if (!isgraph(c) && c != ' ') c = '.';
- *dest++ = c;
- }
- *dest++ = '\0';
-}
-
static void listOfString8(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
int hf_item, int length, guint byte_order)
{
char *s = NULL;
- guint allocated = 0;
proto_item *ti;
proto_tree *tt;
int i;
@@ -2114,11 +2100,7 @@ static void listOfString8(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
while(length--) {
unsigned l = VALUE8(tvb, *offsetp);
- if (allocated < (l + 1)) {
- s = ep_alloc(l + 1);
- allocated = l + 1;
- }
- stringCopy(s, (gchar *)tvb_get_ptr(tvb, *offsetp + 1, l), l); /* Nothing better for now. We need a better string handling API. */
+ s = tvb_get_ephemeral_string(tvb, *offsetp + 1, l);
proto_tree_add_string_format(tt, hf_item, tvb, *offsetp, l + 1, s, "\"%s\"", s);
*offsetp += l + 1;
}
@@ -2141,8 +2123,7 @@ static int stringIsActuallyAn8BitString(tvbuff_t *tvb, int offset, unsigned leng
static void string16_with_buffer_preallocated(tvbuff_t *tvb, proto_tree *t,
int hf, int hf_bytes,
int offset, unsigned length,
- char **s, int *sLength,
- guint byte_order)
+ char **s, guint byte_order)
{
int truncated = FALSE;
unsigned l = length / 2;
@@ -2155,10 +2136,8 @@ static void string16_with_buffer_preallocated(tvbuff_t *tvb, proto_tree *t,
truncated = TRUE;
l = STRING16_MAX_DISPLAYED_LENGTH;
}
- if (*sLength < (int) l + 3) {
- *s = ep_alloc(l + 3);
- *sLength = l + 3;
- }
+
+ *s = ep_alloc(l + 3);
dp = *s;
*dp++ = '"';
if (truncated) l -= 3;
@@ -2184,7 +2163,6 @@ static void string16_with_buffer_preallocated(tvbuff_t *tvb, proto_tree *t,
static void listOfTextItem(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
int sizeIs16, int next_offset, guint byte_order)
{
- int allocated = 0;
char *s = NULL;
proto_item *ti;
proto_tree *tt;
@@ -2218,11 +2196,7 @@ static void listOfTextItem(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
proto_tree *ttt;
gint8 delta = VALUE8(tvb, *offsetp + 1);
if (sizeIs16) l += l;
- if ((unsigned) allocated < l + 1) {
- s = ep_alloc(l + 1);
- allocated = l + 1;
- }
- stringCopy(s, (gchar *)tvb_get_ptr(tvb, *offsetp + 2, l), l);
+ s = tvb_get_ephemeral_string(tvb, *offsetp + 2, l);
tti = proto_tree_add_none_format(tt, hf_x11_textitem_string, tvb, *offsetp, l + 2,
"textitem (string): delta = %d, \"%s\"",
delta, s);
@@ -2232,8 +2206,7 @@ static void listOfTextItem(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
string16_with_buffer_preallocated(tvb, ttt, hf_x11_textitem_string_string16,
hf_x11_textitem_string_string16_bytes,
*offsetp + 2, l,
- &s, &allocated,
- byte_order);
+ &s, byte_order);
else
proto_tree_add_string_format(ttt, hf_x11_textitem_string_string8, tvb,
*offsetp + 2, l, s, "\"%s\"", s);
@@ -2493,13 +2466,7 @@ static void setOfPointerEvent(tvbuff_t *tvb, int *offsetp, proto_tree *t,
static void string8(tvbuff_t *tvb, int *offsetp, proto_tree *t,
int hf, unsigned length)
{
- const guint8 *p;
- char *s;
-
- p = tvb_get_ptr(tvb, *offsetp, length);
- s = ep_alloc(length + 1);
- stringCopy(s, (gchar *)p, length);
- proto_tree_add_string(t, hf, tvb, *offsetp, length, s);
+ proto_tree_add_item(t, hf, tvb, *offsetp, length, ENC_NA|ENC_ASCII);
*offsetp += length;
}
@@ -2509,11 +2476,10 @@ static void string16(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
int hf_bytes, unsigned length, guint byte_order)
{
char *s = NULL;
- gint l = 0;
length += length;
string16_with_buffer_preallocated(tvb, t, hf, hf_bytes, *offsetp, length,
- &s, &l, byte_order);
+ &s, byte_order);
*offsetp += length;
}
@@ -3217,8 +3183,7 @@ static void dissect_x11_request(tvbuff_t *tvb, packet_info *pinfo,
/* necessary processing even if tree == NULL */
v16 = VALUE16(tvb, 4);
- name = se_alloc(v16 + 1);
- stringCopy(name, (gchar*)tvb_get_ptr(tvb, 8, v16), v16);
+ name = tvb_get_ephemeral_string(tvb, 8, v16);
/* store string of extension, opcode will be set at reply */
i = 0;
diff --git a/epan/dissectors/packet-xdmcp.c b/epan/dissectors/packet-xdmcp.c
index 69008047ce..4fc7a975de 100644
--- a/epan/dissectors/packet-xdmcp.c
+++ b/epan/dissectors/packet-xdmcp.c
@@ -96,31 +96,15 @@ static gint ett_xdmcp_authorization_names = -1;
static gint ett_xdmcp_connections = -1;
static gint ett_xdmcp_connection = -1;
-/* Copied from packet-x11.c */
-static void stringCopy(char *dest, const char *source, int length)
-{
- guchar c;
- while(length--) {
- c = *source++;
- if (!isgraph(c) && c != ' ') c = '.';
- *dest++ = c;
- }
- *dest++ = '\0';
-}
-
static gint xdmcp_add_string(proto_tree *tree, gint hf,
tvbuff_t *tvb, gint offset)
{
- const guint8 *p;
char *str;
guint len;
len = tvb_get_ntohs(tvb, offset);
- p = tvb_get_ptr(tvb, offset+2, len);
- str = g_malloc(len+1);
- stringCopy(str, (gchar*)p, len);
+ str = tvb_get_ephemeral_string(tvb, offset+2, len);
proto_tree_add_string(tree, hf, tvb, offset, len+2, str);
- g_free(str);
return len+2;
}
@@ -128,16 +112,12 @@ static gint xdmcp_add_string(proto_tree *tree, gint hf,
static gint xdmcp_add_text(proto_tree *tree, const char *text,
tvbuff_t *tvb, gint offset)
{
- const guint8 *p;
char *str;
guint len;
len = tvb_get_ntohs(tvb, offset);
- p = tvb_get_ptr(tvb, offset+2, len);
- str = g_malloc(len+1);
- stringCopy(str, (gchar*)p, len);
+ str = tvb_get_ephemeral_string(tvb, offset+2, len);
proto_tree_add_text(tree, tvb, offset, len+2, "%s: %s", text, str);
- g_free(str);
return len+2;
}