forked from osmocom/wireshark
wslua: avoid global memory scopes
Use pinfo->pool when available, or allocate/free directly in paths that don't raise exceptions.
This commit is contained in:
parent
65bfe0ccd6
commit
b39fc2aafc
|
@ -551,7 +551,7 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) {
|
|||
rec.block = lua_pinfo->rec->block;
|
||||
}
|
||||
|
||||
data = (const guchar *)tvb_memdup(wmem_packet_scope(),tvb,0,rec.rec_header.packet_header.caplen);
|
||||
data = (const guchar *)tvb_memdup(lua_pinfo->pool,tvb,0,rec.rec_header.packet_header.caplen);
|
||||
|
||||
if (! wtap_dump(d, &rec, data, &err, &err_info)) {
|
||||
switch (err) {
|
||||
|
|
|
@ -186,9 +186,11 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
|
|||
{
|
||||
ByteArray ba = g_byte_array_new();
|
||||
tvbuff_t* tvb = (tvbuff_t *) fvalue_get(&fi->ws_fi->value);
|
||||
guint8* raw;
|
||||
if (tvb != NULL) {
|
||||
g_byte_array_append(ba, (const guint8 *)tvb_memdup(wmem_packet_scope(), tvb, 0,
|
||||
tvb_captured_length(tvb)), tvb_captured_length(tvb));
|
||||
raw = (guint8 *)tvb_memdup(NULL, tvb, 0, tvb_captured_length(tvb));
|
||||
g_byte_array_append(ba, raw, tvb_captured_length(tvb));
|
||||
wmem_free(NULL, raw);
|
||||
}
|
||||
|
||||
pushByteArray(L,ba);
|
||||
|
|
|
@ -223,8 +223,8 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) {
|
|||
tvbr = shiftTvbRange(L,1);
|
||||
if (!tvbr) {
|
||||
/* No TvbRange specified */
|
||||
tvbr = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
|
||||
tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
|
||||
tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange);
|
||||
tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb);
|
||||
tvbr->tvb->ws_tvb = lua_tvb;
|
||||
tvbr->offset = 0;
|
||||
tvbr->len = 0;
|
||||
|
@ -325,8 +325,8 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
|
|||
tvbr = shiftTvbRange(L,1);
|
||||
|
||||
if (!tvbr) {
|
||||
tvbr = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
|
||||
tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
|
||||
tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange);
|
||||
tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb);
|
||||
tvbr->tvb->ws_tvb = lua_tvb;
|
||||
tvbr->offset = 0;
|
||||
tvbr->len = 0;
|
||||
|
@ -760,10 +760,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 = wmem_new(wmem_packet_scope(), struct _wslua_tvbrange);
|
||||
tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange);
|
||||
tvbr->tvb = shiftTvb(L,WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB);
|
||||
if (!tvbr->tvb) {
|
||||
tvbr->tvb = wmem_new(wmem_packet_scope(), struct _wslua_tvb);
|
||||
tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb);
|
||||
}
|
||||
tvbr->tvb->ws_tvb = lua_tvb;
|
||||
tvbr->offset = 0;
|
||||
|
|
|
@ -961,6 +961,7 @@ WSLUA_METHOD TvbRange_string(lua_State* L) {
|
|||
#define WSLUA_OPTARG_TvbRange_string_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_string_ENCODING, ENC_ASCII|ENC_NA);
|
||||
char * str;
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
|
@ -968,7 +969,9 @@ WSLUA_METHOD TvbRange_string(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_pushlstring(L, (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding), tvbr->len);
|
||||
str = (gchar*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding);
|
||||
lua_pushlstring(L, str, tvbr->len);
|
||||
wmem_free(NULL, str);
|
||||
|
||||
WSLUA_RETURN(1); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */
|
||||
}
|
||||
|
@ -984,8 +987,9 @@ static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
str = (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN));
|
||||
str = (gchar*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN));
|
||||
lua_pushlstring(L, str, strlen(str));
|
||||
wmem_free(NULL, str);
|
||||
|
||||
return 1; /* The string */
|
||||
}
|
||||
|
@ -1007,6 +1011,7 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) {
|
|||
guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_stringz_ENCODING, ENC_ASCII|ENC_NA);
|
||||
gint offset;
|
||||
gunichar2 uchar;
|
||||
gchar *str;
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
|
@ -1038,7 +1043,9 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) {
|
|||
break;
|
||||
}
|
||||
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL,encoding));
|
||||
str = (gchar*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,NULL,encoding);
|
||||
lua_pushstring(L, str);
|
||||
wmem_free(NULL, str);
|
||||
|
||||
WSLUA_RETURN(1); /* The string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> up to the first terminating zero. */
|
||||
}
|
||||
|
@ -1098,6 +1105,7 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) {
|
|||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
gint offset;
|
||||
gunichar2 uchar;
|
||||
gchar *str;
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
|
@ -1116,9 +1124,11 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) {
|
|||
offset += 2;
|
||||
} while (uchar != 0);
|
||||
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,&count,
|
||||
(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)) );
|
||||
str = (gchar*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,&count,
|
||||
(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN));
|
||||
lua_pushstring(L, str);
|
||||
lua_pushinteger(L,count);
|
||||
wmem_free(NULL, str);
|
||||
|
||||
return 2; /* The zero terminated string, the length found in tvbr */
|
||||
}
|
||||
|
@ -1155,8 +1165,10 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) {
|
|||
#define WSLUA_OPTARG_TvbRange_bytes_ENCODING 2 /* An optional ENC_* encoding value to use */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
GByteArray* ba;
|
||||
guint8* raw;
|
||||
const guint encoding = (guint)luaL_optinteger(L, WSLUA_OPTARG_TvbRange_bytes_ENCODING, 0);
|
||||
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
luaL_error(L,"expired tvb");
|
||||
|
@ -1165,7 +1177,9 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) {
|
|||
|
||||
if (encoding == 0) {
|
||||
ba = g_byte_array_new();
|
||||
g_byte_array_append(ba,(const guint8 *)tvb_memdup(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len),tvbr->len);
|
||||
raw = (guint8 *)tvb_memdup(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len);
|
||||
g_byte_array_append(ba,raw,tvbr->len);
|
||||
wmem_free(NULL, raw);
|
||||
pushByteArray(L,ba);
|
||||
lua_pushinteger(L, tvbr->len);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue