summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-07-19 22:53:28 -0400
committerEvan Huus <eapache@gmail.com>2016-07-20 22:12:56 +0000
commitbe1398c17ca1d5b203a930d9254125d602830aef (patch)
tree611a6c211931f45a32d65199fa65c4a5a36fec2f
parente07b4aa6670f57be7f613eec9d8d47712d1cfa86 (diff)
downloadwireshark-be1398c17ca1d5b203a930d9254125d602830aef.tar.gz
Convert uses of g_alloced data with tvb_new_child_real_data to use pinfo->pool instead.
Aldo update documentation to suggest using wmem pinfo->pool instead of glib memory Change-Id: I5d34cc6c1515aa9f0d57784b38da501ffcb95ccc Reviewed-on: https://code.wireshark.org/review/16551 Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com> Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Evan Huus <eapache@gmail.com>
-rw-r--r--docbook/wsdg_src/WSDG_chapter_dissection.asciidoc23
-rw-r--r--epan/dissectors/packet-dcp-etsi.c6
-rw-r--r--epan/dissectors/packet-dis.c3
-rw-r--r--epan/dissectors/packet-dvbci.c11
-rw-r--r--epan/dissectors/packet-icq.c6
-rw-r--r--epan/dissectors/packet-isakmp.c11
-rw-r--r--epan/dissectors/packet-osc.c19
-rw-r--r--epan/dissectors/packet-pdcp-lte.c8
-rw-r--r--epan/dissectors/packet-rlc-lte.c3
-rw-r--r--epan/dissectors/packet-selfm.c3
-rw-r--r--epan/dissectors/packet-sysex.c7
-rw-r--r--epan/dissectors/packet-telnet.c3
-rw-r--r--epan/dissectors/packet-zbee-nwk-gp.c20
-rw-r--r--epan/dissectors/packet-zbee-security.c5
14 files changed, 44 insertions, 84 deletions
diff --git a/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc b/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc
index 57ee5ea14f..d50050851e 100644
--- a/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc
+++ b/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc
@@ -577,14 +577,13 @@ effect.
offset ++;
if (flags & FLAG_COMPRESSED) { /* the remainder of the packet is compressed */
guint16 orig_size = tvb_get_ntohs(tvb, offset);
- guchar *decompressed_buffer = (guchar*)g_malloc(orig_size);
+ guchar *decompressed_buffer = (guchar*)wmem_alloc(pinfo->pool, orig_size);
offset += 2;
decompress_packet(tvb_get_ptr(tvb, offset, -1),
tvb_captured_length_remaining(tvb, offset),
decompressed_buffer, orig_size);
/* Now re-setup the tvb buffer to have the new data */
next_tvb = tvb_new_child_real_data(tvb, decompressed_buffer, orig_size, orig_size);
- tvb_set_free_cb(next_tvb, g_free);
add_new_data_source(pinfo, next_tvb, "Decompressed Data");
} else {
next_tvb = tvb_new_subset_remaining(tvb, offset);
@@ -601,19 +600,19 @@ within the protocol. If it's not, it may be part of the compression routine to
work it out for you, in which case the logic would be different.
So armed with the size, a buffer is allocated to receive the uncompressed data
-using +g_malloc()+, and the packet is decompressed into it. The +tvb_get_ptr()+
-function is useful to get a pointer to the raw data of the packet from the
-offset onwards. In this case the decompression routine also needs to know the
-length, which is given by the +tvb_captured_length_remaining()+ function.
+using +wmem_alloc()+ in pinfo->pool memory, and the packet is decompressed into
+it. The +tvb_get_ptr()+ function is useful to get a pointer to the raw data of
+the packet from the offset onwards. In this case the decompression routine also
+needs to know the length, which is given by the
++tvb_captured_length_remaining()+ function.
Next we build a new tvb buffer from this data, using the
+tvb_new_child_real_data()+ call. This data is a child of our original data, so
-calling this function also acknowledges that. One procedural step is to add a
-callback handler to free the data when it's no longer needed via a call to
-+tvb_set_free_cb()+. In this case +g_malloc()+ was used to allocate the memory,
-so +g_free()+ is the appropriate callback function. Finally we add this tvb as a
-new data source, so that the detailed display can show the decompressed bytes as
-well as the original.
+calling this function also acknowledges that. No need to call
++tvb_set_free_cb()+ as the pinfo->pool was used (the memory block will be
+automatically freed when the pinfo pool lifetime expires). Finally we add this
+tvb as a new data source, so that the detailed display can show the
+decompressed bytes as well as the original.
After this has been set up the remainder of the dissector can dissect the buffer
next_tvb, as it's a new buffer the offset needs to be 0 as we start again from
diff --git a/epan/dissectors/packet-dcp-etsi.c b/epan/dissectors/packet-dcp-etsi.c
index 35acba77a7..32cd8588e7 100644
--- a/epan/dissectors/packet-dcp-etsi.c
+++ b/epan/dissectors/packet-dcp-etsi.c
@@ -343,13 +343,12 @@ dissect_pft_fec_detailed(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
tvbuff_t *dtvb = NULL;
const guint8 *input = tvb_get_ptr(new_tvb, 0, -1);
guint32 reassembled_size = tvb_captured_length(new_tvb);
- guint8 *deinterleaved = (guint8*) g_malloc (reassembled_size);
- guint8 *output = (guint8*) g_malloc (decoded_size);
+ guint8 *deinterleaved = (guint8*) wmem_alloc(pinfo->pool, reassembled_size);
+ guint8 *output = (guint8*) wmem_alloc(pinfo->pool, decoded_size);
rs_deinterleave(input, deinterleaved, plen, fcount);
dtvb = tvb_new_child_real_data(tvb, deinterleaved, reassembled_size, reassembled_size);
add_new_data_source(pinfo, dtvb, "Deinterleaved");
- tvb_set_free_cb(dtvb, g_free);
decoded = rs_correct_data(deinterleaved, output, c_max, rsk, rsz);
if(tree)
@@ -357,7 +356,6 @@ dissect_pft_fec_detailed(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
new_tvb = tvb_new_child_real_data(dtvb, output, decoded_size, decoded_size);
add_new_data_source(pinfo, new_tvb, "RS Error Corrected Data");
- tvb_set_free_cb(new_tvb, g_free);
}
return new_tvb;
}
diff --git a/epan/dissectors/packet-dis.c b/epan/dissectors/packet-dis.c
index 00ab7f2021..dcfab75624 100644
--- a/epan/dissectors/packet-dis.c
+++ b/epan/dissectors/packet-dis.c
@@ -4388,7 +4388,7 @@ static gint parse_Link16_Message_Data(proto_tree *tree, tvbuff_t *tvb, gint offs
memset(&state, 0, sizeof(state));
for (i = 0; i < (encodingScheme & 0x3FFF); i++) {
- gint8 *word = (gint8 *)g_malloc(10);
+ gint8 *word = (gint8 *)wmem_alloc(pinfo->pool, 10);
if (!(i & 1)) {
word[0] = (cache >> 16) & 0xFF;
word[1] = (cache >> 24) & 0xFF;
@@ -4424,7 +4424,6 @@ static gint parse_Link16_Message_Data(proto_tree *tree, tvbuff_t *tvb, gint offs
}
newtvb = tvb_new_child_real_data(tvb, word, 10, 10);
- tvb_set_free_cb(newtvb, g_free);
add_new_data_source(pinfo, newtvb, "Link 16 Word");
call_dissector_with_data(link16_handle, newtvb, pinfo, tree, &state);
}
diff --git a/epan/dissectors/packet-dvbci.c b/epan/dissectors/packet-dvbci.c
index e64bd2c55c..a692b5cf40 100644
--- a/epan/dissectors/packet-dvbci.c
+++ b/epan/dissectors/packet-dvbci.c
@@ -2391,7 +2391,7 @@ pref_key_string_to_bin(const gchar *key_string, unsigned char **key_bin)
static tvbuff_t *
-decrypt_sac_msg_body(
+decrypt_sac_msg_body(packet_info *pinfo,
guint8 enc_cip, tvbuff_t *encrypted_tvb, gint offset, gint len)
{
gboolean opened = FALSE;
@@ -2421,7 +2421,7 @@ decrypt_sac_msg_body(
goto end;
clear_len = len;
- clear_data = (unsigned char *)g_malloc(clear_len);
+ clear_data = (unsigned char *)wmem_alloc(pinfo->pool, clear_len);
err = gcry_cipher_decrypt (cipher, clear_data, clear_len,
tvb_memdup(wmem_packet_scope(), encrypted_tvb, offset, len), len);
@@ -2430,13 +2430,10 @@ decrypt_sac_msg_body(
clear_tvb = tvb_new_child_real_data(encrypted_tvb,
(const guint8 *)clear_data, clear_len, clear_len);
- tvb_set_free_cb(clear_tvb, g_free);
end:
if (opened)
gcry_cipher_close (cipher);
- if (!clear_tvb && clear_data)
- g_free(clear_data);
return clear_tvb;
}
@@ -2449,7 +2446,7 @@ pref_key_string_to_bin(const gchar *key_string _U_, unsigned char **key_bin _U_)
}
static tvbuff_t *
-decrypt_sac_msg_body(guint8 enc_cip _U_,
+decrypt_sac_msg_body(packet_info *pinfo _U_, guint8 enc_cip _U_,
tvbuff_t *encrypted_tvb _U_, gint offset _U_, gint len _U_)
{
return NULL;
@@ -3408,7 +3405,7 @@ dissect_sac_msg(guint32 tag, tvbuff_t *tvb, gint offset,
if (tvb_reported_length_remaining(tvb, offset) < 0)
return;
if (enc_flag) {
- clear_sac_body_tvb = decrypt_sac_msg_body(enc_cip,
+ clear_sac_body_tvb = decrypt_sac_msg_body(pinfo, enc_cip,
tvb, offset, tvb_reported_length_remaining(tvb, offset));
}
else {
diff --git a/epan/dissectors/packet-icq.c b/epan/dissectors/packet-icq.c
index fa659c69d8..a7a1124750 100644
--- a/epan/dissectors/packet-icq.c
+++ b/epan/dissectors/packet-icq.c
@@ -1087,17 +1087,13 @@ dissect_icqv5Client(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
*/
rounded_size = ((((capturedsize - ICQ5_CL_SESSIONID) + 3)/4)*4) + ICQ5_CL_SESSIONID;
/* rounded_size might exceed the tvb bounds so we can't just use tvb_memdup here. */
- decr_pd = (guint8 *)g_malloc(rounded_size);
+ decr_pd = (guint8 *)wmem_alloc(pinfo->pool, rounded_size);
tvb_memcpy(tvb, decr_pd, 0, capturedsize);
decrypt_v5(decr_pd, rounded_size, key);
/* Allocate a new tvbuff, referring to the decrypted data. */
decr_tvb = tvb_new_child_real_data(tvb, decr_pd, capturedsize, pktsize);
- /* Arrange that the allocated packet data copy be freed when the
- tvbuff is freed. */
- tvb_set_free_cb(decr_tvb, g_free);
-
/* Add the decrypted data to the data source list. */
add_new_data_source(pinfo, decr_tvb, "Decrypted");
diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c
index c04762a9a1..4b2f1001a8 100644
--- a/epan/dissectors/packet-isakmp.c
+++ b/epan/dissectors/packet-isakmp.c
@@ -1914,16 +1914,14 @@ decrypt_payload(tvbuff_t *tvb, packet_info *pinfo, const guint8 *buf, guint buf_
if (gcry_cipher_setkey(decr_ctx, decr->secret, decr->secret_len))
return NULL;
- decrypted_data = (guint8 *)g_malloc(buf_len);
+ decrypted_data = (guint8 *)wmem_alloc(pinfo->pool, buf_len);
if (gcry_cipher_decrypt(decr_ctx, decrypted_data, buf_len, buf, buf_len) != GPG_ERR_NO_ERROR) {
- g_free(decrypted_data);
return NULL;
}
gcry_cipher_close(decr_ctx);
encr_tvb = tvb_new_child_real_data(tvb, decrypted_data, buf_len, buf_len);
- tvb_set_free_cb(encr_tvb, g_free);
/* Add the decrypted data to the data source list. */
add_new_data_source(pinfo, encr_tvb, "Decrypted IKE");
@@ -5044,7 +5042,7 @@ dissect_enc(tvbuff_t *tvb,
/*
* Allocate buffer for decrypted data.
*/
- decr_data = (guchar*)g_malloc(encr_data_len);
+ decr_data = (guchar*)wmem_alloc(pinfo->pool, encr_data_len);
decr_data_len = encr_data_len;
/*
@@ -5056,28 +5054,24 @@ dissect_enc(tvbuff_t *tvb,
} else {
err = gcry_cipher_open(&cipher_hd, key_info->encr_spec->gcry_alg, key_info->encr_spec->gcry_mode, 0);
if (err) {
- g_free(decr_data);
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"IKEv2 decryption error: algorithm %d, mode %d: gcry_cipher_open failed: %s",
key_info->encr_spec->gcry_alg, key_info->encr_spec->gcry_mode, gcry_strerror(err)));
}
err = gcry_cipher_setkey(cipher_hd, key_info->encr_key, key_info->encr_spec->key_len);
if (err) {
- g_free(decr_data);
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"IKEv2 decryption error: algorithm %d, key length %d: gcry_cipher_setkey failed: %s",
key_info->encr_spec->gcry_alg, key_info->encr_spec->key_len, gcry_strerror(err)));
}
err = gcry_cipher_setiv(cipher_hd, iv, iv_len);
if (err) {
- g_free(decr_data);
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"IKEv2 decryption error: algorithm %d, iv length %d: gcry_cipher_setiv failed: %s",
key_info->encr_spec->gcry_alg, iv_len, gcry_strerror(err)));
}
err = gcry_cipher_decrypt(cipher_hd, decr_data, decr_data_len, encr_data, encr_data_len);
if (err) {
- g_free(decr_data);
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"IKEv2 decryption error: algorithm %d: gcry_cipher_decrypt failed: %s",
key_info->encr_spec->gcry_alg, gcry_strerror(err)));
@@ -5086,7 +5080,6 @@ dissect_enc(tvbuff_t *tvb,
}
decr_tvb = tvb_new_child_real_data(tvb, decr_data, decr_data_len, decr_data_len);
- tvb_set_free_cb(decr_tvb, g_free);
add_new_data_source(pinfo, decr_tvb, "Decrypted Data");
item = proto_tree_add_item(tree, hf_isakmp_enc_decrypted_data, decr_tvb, 0, decr_data_len, ENC_NA);
proto_item_append_text(item, " (%d byte%s)", decr_data_len, plurality(decr_data_len, "", "s"));
diff --git a/epan/dissectors/packet-osc.c b/epan/dissectors/packet-osc.c
index c0e21d550c..e4170a942a 100644
--- a/epan/dissectors/packet-osc.c
+++ b/epan/dissectors/packet-osc.c
@@ -979,21 +979,14 @@ dissect_osc_tcp_1_1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
decoded_len = slip_decoded_len(encoded_buf, encoded_len);
if(decoded_len != -1) /* is a valid SLIP'd stream */
{
- decoded_buf = (guint8 *)g_malloc(decoded_len);
- if(decoded_buf)
- {
- slip_decode(decoded_buf, encoded_buf, encoded_len);
+ decoded_buf = (guint8 *)wmem_alloc(pinfo->pool, decoded_len);
- next_tvb = tvb_new_child_real_data(tvb, decoded_buf, decoded_len, decoded_len);
- tvb_set_free_cb(next_tvb, g_free);
+ slip_decode(decoded_buf, encoded_buf, encoded_len);
- add_new_data_source(pinfo, next_tvb, "SLIP-decoded Data");
- dissect_osc_pdu_common(next_tvb, pinfo, tree, data, 0, decoded_len);
- }
- else
- {
- return 0; /* failed to allocate new buffer */
- }
+ next_tvb = tvb_new_child_real_data(tvb, decoded_buf, decoded_len, decoded_len);
+
+ add_new_data_source(pinfo, next_tvb, "SLIP-decoded Data");
+ dissect_osc_pdu_common(next_tvb, pinfo, tree, data, 0, decoded_len);
}
else
{
diff --git a/epan/dissectors/packet-pdcp-lte.c b/epan/dissectors/packet-pdcp-lte.c
index 8a1fd7fe13..b98316aac8 100644
--- a/epan/dissectors/packet-pdcp-lte.c
+++ b/epan/dissectors/packet-pdcp-lte.c
@@ -1540,8 +1540,7 @@ static tvbuff_t *decipher_payload(tvbuff_t *tvb, packet_info *pinfo, int *offset
/* Extract the encrypted data into a buffer */
payload_length = tvb_captured_length_remaining(tvb, *offset);
- decrypted_data = (guint8 *)g_malloc0(payload_length);
- tvb_memcpy(tvb, decrypted_data, *offset, payload_length);
+ decrypted_data = (guint8 *)tvb_memdup(pinfo->pool, tvb, *offset, payload_length);
/* Decrypt the actual data */
gcrypt_err = gcry_cipher_decrypt(cypher_hd,
@@ -1549,7 +1548,6 @@ static tvbuff_t *decipher_payload(tvbuff_t *tvb, packet_info *pinfo, int *offset
NULL, 0);
if (gcrypt_err != 0) {
gcry_cipher_close(cypher_hd);
- g_free(decrypted_data);
return tvb;
}
@@ -1563,8 +1561,7 @@ static tvbuff_t *decipher_payload(tvbuff_t *tvb, packet_info *pinfo, int *offset
if (pdu_security_settings->ciphering == eea1) {
/* Extract the encrypted data into a buffer */
payload_length = tvb_captured_length_remaining(tvb, *offset);
- decrypted_data = (guint8 *)g_malloc0(payload_length+4);
- tvb_memcpy(tvb, decrypted_data, *offset, payload_length);
+ decrypted_data = (guint8 *)tvb_memdup(pinfo->pool, tvb, *offset, payload_length);
/* Do the algorithm */
snow3g_f8(pdu_security_settings->cipherKey,
@@ -1577,7 +1574,6 @@ static tvbuff_t *decipher_payload(tvbuff_t *tvb, packet_info *pinfo, int *offset
/* Create tvb for resulting deciphered sdu */
decrypted_tvb = tvb_new_child_real_data(tvb, decrypted_data, payload_length, payload_length);
- tvb_set_free_cb(decrypted_tvb, g_free);
add_new_data_source(pinfo, decrypted_tvb, "Deciphered Payload");
/* Return deciphered data, i.e. beginning of new tvb */
diff --git a/epan/dissectors/packet-rlc-lte.c b/epan/dissectors/packet-rlc-lte.c
index aab7cfe832..296a081c67 100644
--- a/epan/dissectors/packet-rlc-lte.c
+++ b/epan/dissectors/packet-rlc-lte.c
@@ -524,7 +524,7 @@ static tvbuff_t* reassembly_get_reassembled_tvb(rlc_channel_reassembly_info *rea
for (n=0; n < reassembly_info->number_of_segments; n++) {
combined_length += reassembly_info->segments[n].length;
}
- combined_data = (guint8 *)g_malloc(combined_length);
+ combined_data = (guint8 *)wmem_alloc(pinfo->pool, combined_length);
/* Copy data into contiguous buffer */
for (n=0; n < reassembly_info->number_of_segments; n++) {
@@ -536,7 +536,6 @@ static tvbuff_t* reassembly_get_reassembled_tvb(rlc_channel_reassembly_info *rea
/* Create and return tvb with this data */
reassembled_tvb = tvb_new_child_real_data(parent_tvb, combined_data, combined_offset, combined_offset);
- tvb_set_free_cb(reassembled_tvb, g_free);
add_new_data_source(pinfo, reassembled_tvb, "Reassembled SDU");
return reassembled_tvb;
}
diff --git a/epan/dissectors/packet-selfm.c b/epan/dissectors/packet-selfm.c
index e91f0013ac..d706c7ace9 100644
--- a/epan/dissectors/packet-selfm.c
+++ b/epan/dissectors/packet-selfm.c
@@ -834,7 +834,7 @@ clean_telnet_iac(packet_info *pinfo, tvbuff_t *tvb, int offset, int len)
int skip_byte, len_remaining;
spos=tvb_get_ptr(tvb, offset, len);
- buf=(guint8 *)g_malloc(len);
+ buf=(guint8 *)wmem_alloc(pinfo->pool, len);
dpos=buf;
skip_byte = 0;
len_remaining = len;
@@ -857,7 +857,6 @@ clean_telnet_iac(packet_info *pinfo, tvbuff_t *tvb, int offset, int len)
len_remaining--;
}
telnet_tvb = tvb_new_child_real_data(tvb, buf, len-skip_byte, len-skip_byte);
- tvb_set_free_cb(telnet_tvb, g_free);
add_new_data_source(pinfo, telnet_tvb, "Processed Telnet Data");
return telnet_tvb;
diff --git a/epan/dissectors/packet-sysex.c b/epan/dissectors/packet-sysex.c
index 977de361c5..f8d1a7414c 100644
--- a/epan/dissectors/packet-sysex.c
+++ b/epan/dissectors/packet-sysex.c
@@ -734,7 +734,7 @@ static value_string_ext digitech_parameter_positions_ext =
VALUE_STRING_EXT_INIT(digitech_parameter_positions);
static tvbuff_t *
-unpack_digitech_message(tvbuff_t *tvb, gint offset)
+unpack_digitech_message(packet_info *pinfo, tvbuff_t *tvb, gint offset)
{
tvbuff_t *next_tvb;
gint length = tvb_reported_length(tvb);
@@ -754,7 +754,7 @@ unpack_digitech_message(tvbuff_t *tvb, gint offset)
}
data_ptr = tvb_get_ptr(tvb, offset, data_len);
- unpacked = (guchar*)g_malloc(unpacked_size);
+ unpacked = (guchar*)wmem_alloc(pinfo->pool, unpacked_size);
unpacked_ptr = unpacked;
while (remaining > 0)
@@ -772,7 +772,6 @@ unpack_digitech_message(tvbuff_t *tvb, gint offset)
/* Create new tvb with unpacked data */
next_tvb = tvb_new_child_real_data(tvb, unpacked, unpacked_size, unpacked_size);
- tvb_set_free_cb(next_tvb, g_free);
return next_tvb;
}
@@ -979,7 +978,7 @@ dissect_digitech_procedure(guint8 procedure, const gint offset,
return;
}
- data_tvb = unpack_digitech_message(tvb, offset);
+ data_tvb = unpack_digitech_message(pinfo, tvb, offset);
add_new_data_source(pinfo, data_tvb, "Unpacked Procedure Data");
data_offset = 0;
diff --git a/epan/dissectors/packet-telnet.c b/epan/dissectors/packet-telnet.c
index 7345d080b7..577b9660df 100644
--- a/epan/dissectors/packet-telnet.c
+++ b/epan/dissectors/packet-telnet.c
@@ -1050,7 +1050,7 @@ unescape_and_tvbuffify_telnet_option(packet_info *pinfo, tvbuff_t *tvb, int offs
return NULL;
spos=tvb_get_ptr(tvb, offset, len);
- buf=(guint8 *)g_malloc(len);
+ buf=(guint8 *)wmem_alloc(pinfo->pool, len);
dpos=buf;
skip=0;
l=len;
@@ -1066,7 +1066,6 @@ unescape_and_tvbuffify_telnet_option(packet_info *pinfo, tvbuff_t *tvb, int offs
l--;
}
krb5_tvb = tvb_new_child_real_data(tvb, buf, len-skip, len-skip);
- tvb_set_free_cb(krb5_tvb, g_free);
add_new_data_source(pinfo, krb5_tvb, "Unpacked Telnet Option");
return krb5_tvb;
diff --git a/epan/dissectors/packet-zbee-nwk-gp.c b/epan/dissectors/packet-zbee-nwk-gp.c
index 14c48d213a..9943d171da 100644
--- a/epan/dissectors/packet-zbee-nwk-gp.c
+++ b/epan/dissectors/packet-zbee-nwk-gp.c
@@ -1287,26 +1287,22 @@ dissect_zbee_nwk_gp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
THROW(BoundsError);
}
if (packet.security_level == ZBEE_NWK_GP_SECURITY_LEVEL_FULLENCR) {
- dec_buffer = (guint8 *)g_malloc(packet.payload_len);
+ dec_buffer = (guint8 *)wmem_alloc(pinfo->pool, packet.payload_len);
gp_decrypted = FALSE;
- if (packet.security_level == ZBEE_NWK_GP_SECURITY_LEVEL_FULLENCR) {
- GSList_i = zbee_gp_keyring;
- while (GSList_i && !gp_decrypted) {
- gp_decrypted = zbee_gp_decrypt_payload(&packet, enc_buffer, offset - packet.payload_len -
- packet.mic_size, dec_buffer, packet.payload_len, packet.mic_size,
- ((key_record_t *)(GSList_i->data))->key);
- if (!gp_decrypted) {
- GSList_i = g_slist_next(GSList_i);
- }
+ GSList_i = zbee_gp_keyring;
+ while (GSList_i && !gp_decrypted) {
+ gp_decrypted = zbee_gp_decrypt_payload(&packet, enc_buffer, offset - packet.payload_len -
+ packet.mic_size, dec_buffer, packet.payload_len, packet.mic_size,
+ ((key_record_t *)(GSList_i->data))->key);
+ if (!gp_decrypted) {
+ GSList_i = g_slist_next(GSList_i);
}
}
if (gp_decrypted) {
payload_tvb = tvb_new_child_real_data(tvb, dec_buffer, packet.payload_len, packet.payload_len);
add_new_data_source(pinfo, payload_tvb, "Decrypted GP Payload");
dissect_zbee_nwk_gp_cmd(payload_tvb, pinfo, nwk_tree, data);
- g_free(dec_buffer);
} else {
- g_free(dec_buffer);
payload_tvb = tvb_new_subset(tvb, offset - packet.payload_len - packet.mic_size, packet.payload_len, -1);
call_data_dissector(payload_tvb, pinfo, tree);
}
diff --git a/epan/dissectors/packet-zbee-security.c b/epan/dissectors/packet-zbee-security.c
index 00f9bbbaf2..38d245f0e8 100644
--- a/epan/dissectors/packet-zbee-security.c
+++ b/epan/dissectors/packet-zbee-security.c
@@ -648,7 +648,7 @@ dissect_zbee_secure(tvbuff_t *tvb, packet_info *pinfo, proto_tree* tree, guint o
}
/* Allocate memory to decrypt the payload into. */
- dec_buffer = (guint8 *)g_malloc(payload_len);
+ dec_buffer = (guint8 *)wmem_alloc(pinfo->pool, payload_len);
decrypted = FALSE;
if ( packet.src64 ) {
@@ -748,14 +748,11 @@ dissect_zbee_secure(tvbuff_t *tvb, packet_info *pinfo, proto_tree* tree, guint o
/* Found a key that worked, setup the new tvbuff_t and return */
payload_tvb = tvb_new_child_real_data(tvb, dec_buffer, payload_len, payload_len);
- tvb_set_free_cb(payload_tvb, g_free); /* set up callback to free dec_buffer */
add_new_data_source(pinfo, payload_tvb, "Decrypted ZigBee Payload");
/* Done! */
return payload_tvb;
}
-
- g_free(dec_buffer);
#endif /* HAVE_LIBGCRYPT */
/* Add expert info. */