aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHadriel Kaplan <hadriel@128technology.com>2014-12-29 00:21:15 -0500
committerMichael Mann <mmann78@netscape.net>2015-01-04 21:02:38 +0000
commitfac8356610fadf488ff92c5a22e5177bb33a2511 (patch)
treeaf8a1ceec7eb91c5a6a5e6e2ac14621425125e65
parent5653fcedca8491829d6d6ce480e7fba13ff801d7 (diff)
Make all Lua code use wmem not emem
Changed all remaining code in wslua that was using emem, to use wmem or simpler methods. Bug: 9927 Change-Id: I3d19a770e0fd77d996bdb6b61a76a722cc2bcd55 Reviewed-on: https://code.wireshark.org/review/6109 Petri-Dish: Michael Mann <mmann78@netscape.net> Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--debian/libwireshark0.symbols3
-rw-r--r--epan/addr_resolv.c22
-rw-r--r--epan/addr_resolv.h7
-rw-r--r--epan/to_str.c27
-rw-r--r--epan/to_str.h5
-rw-r--r--epan/tvbuff.c9
-rw-r--r--epan/tvbuff.h6
-rw-r--r--epan/wslua/wslua_field.c1
-rw-r--r--epan/wslua/wslua_gui.c7
-rw-r--r--epan/wslua/wslua_listener.c14
-rw-r--r--epan/wslua/wslua_pinfo.c9
-rw-r--r--epan/wslua/wslua_proto.c9
-rw-r--r--epan/wslua/wslua_tree.c14
-rw-r--r--epan/wslua/wslua_tvb.c25
14 files changed, 117 insertions, 41 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols
index eb52e6bed2..199a30786a 100644
--- a/debian/libwireshark0.symbols
+++ b/debian/libwireshark0.symbols
@@ -76,6 +76,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
byte_array_equal@Base 1.9.1
bytes_to_ep_str@Base 1.12.0~rc1
bytes_to_ep_str_punct@Base 1.12.0~rc1
+ bytes_to_str@Base 1.99.2
bytestring_to_ep_str@Base 1.12.0~rc1
bytestring_to_str@Base 1.9.1
call_ber_oid_callback@Base 1.9.1
@@ -1296,6 +1297,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
tvb_bytes_exist@Base 1.9.1
tvb_bytes_to_ep_str@Base 1.12.0~rc1
tvb_bytes_to_ep_str_punct@Base 1.12.0~rc1
+ tvb_bytes_to_wmem_str@Base 1.99.2
tvb_captured_length@Base 1.12.0~rc1
tvb_captured_length_remaining@Base 1.12.0~rc1
tvb_child_uncompress@Base 1.12.0~rc1
@@ -1453,6 +1455,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
value_is_in_range@Base 1.9.1
value_string_ext_free@Base 1.12.0~rc1
value_string_ext_new@Base 1.9.1
+ wmem_address_to_display@Base 1.99.2
wmem_alloc0@Base 1.9.1
wmem_alloc@Base 1.9.1
wmem_allocator_new@Base 1.9.1
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index 7a8d5b30bc..f78b6f7044 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -2903,6 +2903,28 @@ ep_address_to_display(const address *addr)
}
const gchar *
+wmem_address_to_display(wmem_allocator_t *allocator, const address *addr)
+{
+ gchar *str = NULL;
+ const gchar *result = solve_address_to_name(addr);
+
+ if (result != NULL) {
+ /* unlike ep_address_to_display(), we can't assume the lifetime of the address' members
+ is safe, so we allocate and copy */
+ str = wmem_strdup(allocator, result);
+ }
+ else if (addr->type == AT_NONE) {
+ str = wmem_strdup(allocator, "NONE");
+ }
+ else {
+ str = (gchar *) wmem_alloc(allocator, MAX_ADDR_STR_LEN);
+ address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
+ }
+
+ return str;
+}
+
+const gchar *
get_addr_name(const address *addr)
{
guint32 ip4_addr;
diff --git a/epan/addr_resolv.h b/epan/addr_resolv.h
index 0f92484f5b..140cc8703c 100644
--- a/epan/addr_resolv.h
+++ b/epan/addr_resolv.h
@@ -144,6 +144,13 @@ WS_DLL_PUBLIC gchar *ep_sctp_port_to_display(guint port);
WS_DLL_PUBLIC
const gchar *ep_address_to_display(const address *addr);
+/*
+ * wmem_address_to_display is the same as ep_address_to_display above, but
+ * using the wmem scope for memory management.
+ */
+WS_DLL_PUBLIC
+const gchar *wmem_address_to_display(wmem_allocator_t *allocator, const address *addr);
+
/* get_addr_name_buf solves an address in the same way as ep_address_to_display above */
/* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
/* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
diff --git a/epan/to_str.c b/epan/to_str.c
index c12e58b3f3..69d741ecff 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -252,6 +252,33 @@ bytes_to_ep_str(const guint8 *bd, int bd_len)
return cur;
}
+char *
+bytes_to_str(wmem_allocator_t *allocator, const guint8 *bd, int bd_len)
+{
+ gchar *cur;
+ gchar *cur_ptr;
+ int truncated = 0;
+
+ if (!bd)
+ REPORT_DISSECTOR_BUG("Null pointer passed to bytes_to_str()");
+
+ cur=(gchar *)wmem_alloc(allocator, MAX_BYTE_STR_LEN+3+1);
+ if (bd_len <= 0) { cur[0] = '\0'; return cur; }
+
+ if (bd_len > MAX_BYTE_STR_LEN/2) { /* bd_len > 24 */
+ truncated = 1;
+ bd_len = MAX_BYTE_STR_LEN/2;
+ }
+
+ cur_ptr = bytes_to_hexstr(cur, bd, bd_len); /* max MAX_BYTE_STR_LEN bytes */
+
+ if (truncated)
+ cur_ptr = g_stpcpy(cur_ptr, "..."); /* 3 bytes */
+
+ *cur_ptr = '\0'; /* 1 byte */
+ return cur;
+}
+
/* Turn an array of bytes into a string showing the bytes in hex with
* punct as a bytes separator.
*/
diff --git a/epan/to_str.h b/epan/to_str.h
index 0f1ab5b559..be2de0f0a1 100644
--- a/epan/to_str.h
+++ b/epan/to_str.h
@@ -106,6 +106,11 @@ WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
*/
WS_DLL_PUBLIC gchar *bytes_to_ep_str(const guint8 *bd, int bd_len);
+/**
+ * Same as above, but using wmem memory management.
+ */
+WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *allocator, const guint8 *bd, int bd_len);
+
/** Turn an array of bytes into a string showing the bytes in hex,
* separated by a punctuation character.
*
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index fce1f3fa72..111b0ba0a1 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -3488,6 +3488,15 @@ tvb_bytes_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len)
return bytes_to_ep_str(ensure_contiguous(tvb, offset, len), len);
}
+/*
+ * Same as tvb_bytes_to_ep_str but with wmem
+ */
+gchar *tvb_bytes_to_wmem_str(wmem_allocator_t *allocator, tvbuff_t *tvb,
+ const gint offset, const gint len)
+{
+ return bytes_to_str(allocator, ensure_contiguous(tvb, offset, len), len);
+}
+
/* Find a needle tvbuff within a haystack tvbuff. */
gint
tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, const gint haystack_offset)
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index 66fd060d13..a478e42058 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -854,6 +854,12 @@ WS_DLL_PUBLIC gchar *tvb_bytes_to_ep_str(tvbuff_t *tvb, const gint offset,
const gint len);
/**
+ * Same as above, but using wmem memory management
+ */
+WS_DLL_PUBLIC gchar *tvb_bytes_to_wmem_str(wmem_allocator_t *allocator, tvbuff_t *tvb,
+ const gint offset, const gint len);
+
+/**
* Given a tvbuff, an offset into the tvbuff, and a length that starts
* at that offset (which may be -1 for "all the way to the end of the
* tvbuff"), fetch BCD encoded digits from a tvbuff starting from either
diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c
index e2f6928cf8..5fe0715bba 100644
--- a/epan/wslua/wslua_field.c
+++ b/epan/wslua/wslua_field.c
@@ -26,7 +26,6 @@
#include "config.h"
-#include <epan/emem.h>
#include <epan/dfilter/dfilter.h>
#include <epan/ftypes/ftypes-int.h>
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index 56efdac858..b73564eff9 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -361,13 +361,10 @@ WSLUA_METHOD ProgDlg_close(lua_State* L) { /* Closes the progress dialog. */
static int ProgDlg__tostring(lua_State* L) {
ProgDlg pd = checkProgDlg(L,1);
- char *str;
- str = wmem_strdup_printf(NULL, "%sstopped",pd->stopped?"":"not ");
- lua_pushstring(L, str);
- wmem_free(NULL, str);
+ lua_pushfstring(L, "%sstopped",pd->stopped?"":"not ");
- return 0;
+ WSLUA_RETURN(1); /* A string specifying whether the Progress Dialog has stopped or not. */
}
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c
index 5e0deb6307..dd76825b0e 100644
--- a/epan/wslua/wslua_listener.c
+++ b/epan/wslua/wslua_listener.c
@@ -28,8 +28,6 @@
#include "config.h"
-#include <epan/emem.h>
-
/* WSLUA_MODULE Listener Post-dissection packet analysis */
#include "wslua.h"
@@ -47,9 +45,8 @@ static int tap_packet_cb_error_handler(lua_State* L) {
static int repeated = 0;
static int next = 2;
const gchar* where = (lua_pinfo) ?
-
- ep_strdup_printf("Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->fd->num) :
- ep_strdup_printf("Lua: Error During execution of Listener Packet Callback") ;
+ wmem_strdup_printf(NULL, "Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->fd->num) :
+ wmem_strdup_printf(NULL, "Lua: Error During execution of Listener Packet Callback") ;
/* show the error the 1st, 3rd, 5th, 9th, 17th, 33th... time it appears to avoid window flooding */
/* XXX the last series of identical errors won't be shown (the user however gets at least one message) */
@@ -59,6 +56,8 @@ static int tap_packet_cb_error_handler(lua_State* L) {
last_error = g_strdup(error);
repeated = 0;
next = 2;
+ wmem_free(NULL, (void*) where);
+ where = NULL;
return 0;
}
@@ -77,6 +76,7 @@ static int tap_packet_cb_error_handler(lua_State* L) {
report_failure("%s:\n %s",where,error);
}
+ wmem_free(NULL, (void*) where);
return 0;
}
@@ -288,10 +288,8 @@ WSLUA_METHOD Listener_remove(lua_State* L) {
WSLUA_METAMETHOD Listener__tostring(lua_State* L) {
/* Generates a string of debug info for the tap `Listener`. */
Listener tap = checkListener(L,1);
- gchar* str;
- str = ep_strdup_printf("Listener(%s) filter: %s",tap->name, tap->filter ? tap->filter : "NONE");
- lua_pushstring(L,str);
+ lua_pushfstring(L,"Listener(%s) filter: %s",tap->name, tap->filter ? tap->filter : "NONE");
return 1;
}
diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c
index 06a022ed78..98bdee9ce4 100644
--- a/epan/wslua/wslua_pinfo.c
+++ b/epan/wslua/wslua_pinfo.c
@@ -380,8 +380,11 @@ WSLUA_METHODS Address_methods[] = {
WSLUA_METAMETHOD Address__tostring(lua_State* L) {
Address addr = checkAddress(L,1);
+ const gchar *str = wmem_address_to_display(NULL, addr);
- lua_pushstring(L,ep_address_to_display(addr));
+ lua_pushstring(L, str);
+
+ wmem_free(NULL, (void*) str);
WSLUA_RETURN(1); /* The string representing the address. */
}
@@ -837,7 +840,7 @@ static int PrivateTable__newindex(lua_State* L) {
}
if (string) {
- g_hash_table_replace (priv->table, (gpointer) ep_strdup(name), (gpointer) ep_strdup(string));
+ g_hash_table_replace (priv->table, (gpointer) g_strdup(name), (gpointer) g_strdup(string));
} else {
g_hash_table_remove (priv->table, (gconstpointer) name);
}
@@ -1059,7 +1062,7 @@ static int Pinfo_get_private(lua_State *L) {
gboolean is_allocated = FALSE;
if (!pinfo->ws_pinfo->private_table) {
- pinfo->ws_pinfo->private_table = g_hash_table_new(g_str_hash,g_str_equal);
+ pinfo->ws_pinfo->private_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
is_allocated = TRUE;
}
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c
index afa4526bbe..7c24d28313 100644
--- a/epan/wslua/wslua_proto.c
+++ b/epan/wslua/wslua_proto.c
@@ -27,8 +27,6 @@
#include "config.h"
-#include <epan/emem.h>
-
/* WSLUA_MODULE Proto Functions for new protocols and dissectors
The classes and functions in this chapter allow Lua scripts to create new
@@ -1324,12 +1322,13 @@ PROTOFIELD_OTHER(eui64,FT_EUI64)
WSLUA_METAMETHOD ProtoField__tostring(lua_State* L) {
/* Returns a string with info about a protofield (for debugging purposes). */
ProtoField f = checkProtoField(L,1);
- gchar* s = (gchar *)ep_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s",
+ gchar* s = g_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s",
f->hfid,f->name,f->abbr,
ftenum_to_string(f->type),
base_to_string(f->base),
f->vs,f->mask,f->blob);
lua_pushstring(L,s);
+ g_free(s);
return 1;
}
@@ -1584,10 +1583,8 @@ WSLUA_METAMETHOD Proto__call(lua_State* L) { /* Creates a `Proto` object. */
static int Proto__tostring(lua_State* L) {
Proto proto = checkProto(L,1);
- gchar* s;
- s = ep_strdup_printf("Proto: %s",proto->name);
- lua_pushstring(L,s);
+ lua_pushfstring(L, "Proto: %s", proto->name);
return 1;
}
diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c
index 5d8aac895b..6958d3e21e 100644
--- a/epan/wslua/wslua_tree.c
+++ b/epan/wslua/wslua_tree.c
@@ -27,8 +27,6 @@
#include "config.h"
-#include <epan/emem.h>
-
/* WSLUA_MODULE Tree Adding information to the dissection tree */
#include "wslua.h"
@@ -201,8 +199,8 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) {
tvbr = shiftTvbRange(L,1);
if (!tvbr) {
/* No TvbRange specified */
- tvbr = ep_new(struct _wslua_tvbrange);
- tvbr->tvb = ep_new(struct _wslua_tvb);
+ tvbr = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
+ tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
tvbr->tvb->ws_tvb = lua_tvb;
tvbr->offset = 0;
tvbr->len = 0;
@@ -302,8 +300,8 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
tvbr = shiftTvbRange(L,1);
if (!tvbr) {
- tvbr = ep_new(struct _wslua_tvbrange);
- tvbr->tvb = ep_new(struct _wslua_tvb);
+ tvbr = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
+ tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
tvbr->tvb->ws_tvb = lua_tvb;
tvbr->offset = 0;
tvbr->len = 0;
@@ -608,10 +606,10 @@ WSLUA_METHOD TreeItem_add_tvb_expert_info(lua_State *L) {
tvbr = shiftTvbRange(L,WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB);
if (!tvbr) {
- tvbr = ep_new(struct _wslua_tvbrange);
+ tvbr = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
tvbr->tvb = shiftTvb(L,WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB);
if (!tvbr->tvb) {
- tvbr->tvb = ep_new(struct _wslua_tvb);
+ tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
}
tvbr->tvb->ws_tvb = lua_tvb;
tvbr->offset = 0;
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index 8d0a359050..489690ad6c 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -498,16 +498,16 @@ WSLUA_CONSTRUCTOR TvbRange_tvb (lua_State *L) {
}
WSLUA_METAMETHOD Tvb__tostring(lua_State* L) {
- /* Convert the bytes of a `Tvb` into a string, to be used for debugging purposes as '...'
- will be appended in case the string is too long. */
+ /* Convert the bytes of a `Tvb` into a string, to be used for debugging purposes, as '...'
+ will be appended if the string is too long. */
Tvb tvb = checkTvb(L,1);
- int len;
- gchar* str;
+ int len = tvb_captured_length(tvb->ws_tvb);
+ char* str = tvb_bytes_to_wmem_str(NULL,tvb->ws_tvb,0,len);
+
+ lua_pushfstring(L, "TVB(%d) : %s", len, str);
- len = tvb_captured_length(tvb->ws_tvb);
- str = wmem_strdup_printf(NULL, "TVB(%i) : %s",len,tvb_bytes_to_ep_str(tvb->ws_tvb,0,len));
- lua_pushstring(L,str);
wmem_free(NULL, str);
+
WSLUA_RETURN(1); /* The string. */
}
@@ -1554,10 +1554,11 @@ WSLUA_METHOD TvbRange_raw(lua_State* L) {
WSLUA_METAMETHOD TvbRange__tostring(lua_State* L) {
- /* Converts the `TvbRange` into a string. As the string gets truncated
+ /* Converts the `TvbRange` into a string. Since the string gets truncated,
you should use this only for debugging purposes
or if what you want is to have a truncated string in the format 67:89:AB:... */
TvbRange tvbr = checkTvbRange(L,1);
+ char* str = NULL;
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
@@ -1565,8 +1566,12 @@ WSLUA_METAMETHOD TvbRange__tostring(lua_State* L) {
return 0;
}
- lua_pushstring(L,tvb_bytes_to_ep_str(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len));
- return 1;
+ str = tvb_bytes_to_wmem_str(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len);
+
+ lua_pushstring(L,str);
+ wmem_free(NULL, str);
+
+ WSLUA_RETURN(1); /* A Lua hex string of the first 24 binary bytes in the `TvbRange`. */
}
WSLUA_METHODS TvbRange_methods[] = {