diff options
author | João Valverde <j@v6e.pt> | 2016-02-08 00:43:56 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2016-02-08 00:44:22 +0000 |
commit | ef929dc8eb8c61d5829132d2da2a3061df44bba9 (patch) | |
tree | 6dc7fb0abec832c1b336580bfeaec70717f0a76f /epan/address.h | |
parent | 8df2857bc1082797cc7052eb5a6ebb45ac92e4b9 (diff) | |
download | wireshark-ef929dc8eb8c61d5829132d2da2a3061df44bba9.tar.gz wireshark-ef929dc8eb8c61d5829132d2da2a3061df44bba9.tar.bz2 wireshark-ef929dc8eb8c61d5829132d2da2a3061df44bba9.zip |
Revert "Add free_address_wmem() and other extensions to address API"
This reverts commit 13ec77a9fc3af3b0b502820d0b55796c89997896.
This commit introduces a segmentation fault for Lua code (uncovered by the test suite).
Change-Id: Ibc273d1915cda9632697b9f138f0ae104d3fb65e
Reviewed-on: https://code.wireshark.org/review/13813
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'epan/address.h')
-rw-r--r-- | epan/address.h | 132 |
1 files changed, 33 insertions, 99 deletions
diff --git a/epan/address.h b/epan/address.h index 027bc0fef0..f0a42c1eee 100644 --- a/epan/address.h +++ b/epan/address.h @@ -63,24 +63,9 @@ typedef enum { typedef struct _address { int type; /* type of address */ int len; /* length of address, in bytes */ - const void *data; /* pointer to address data */ - - /* private */ - void *priv; + const void *data; /* pointer to address data */ } address; -#define ADDRESS_INIT(type, len, data) {type, len, data, NULL} -#define ADDRESS_INIT_NONE ADDRESS_INIT(AT_NONE, 0, NULL) - -static inline void -clear_address(address *addr) -{ - addr->type = AT_NONE; - addr->len = -1; - addr->data = NULL; - addr->priv = NULL; -} - /** Initialize an address with the given values. * * @param addr [in,out] The address to initialize. @@ -91,10 +76,9 @@ clear_address(address *addr) */ static inline void set_address(address *addr, int addr_type, int addr_len, const void *addr_data) { + addr->data = addr_data; addr->type = addr_type; addr->len = addr_len; - addr->data = addr_data; - addr->priv = NULL; } /** Initialize an address from TVB data. @@ -120,46 +104,6 @@ set_address_tvb(address *addr, int addr_type, int addr_len, tvbuff_t *tvb, int o set_address(addr, addr_type, addr_len, p); } -/** Initialize an address with the given values, allocating a new buffer - * for the address data using wmem-scoped memory. - * - * @param scope [in] The lifetime of the allocated memory, e.g., wmem_packet_scope() - * @param addr [in,out] The address to initialize. - * @param addr_type [in] Address type. - * @param addr_len [in] The length in bytes of the address data. For example, 4 for - * AT_IPv4 or sizeof(struct e_in6_addr) for AT_IPv6. - * @param addr_data [in] Pointer to the address data. - */ -static inline void -alloc_address_wmem(wmem_allocator_t *scope, address *addr, - int addr_type, int addr_len, const void *addr_data) { - addr->type = addr_type; - addr->len = addr_len; - addr->priv = wmem_memdup(scope, addr_data, addr->len); - addr->data = addr->priv; -} - -/** Allocate an address from TVB data. - * - * Same as alloc_address_wmem but it takes a TVB and an offset. - * - * @param scope [in] The lifetime of the allocated memory, e.g., wmem_packet_scope() - * @param addr [in,out] The address to initialize. - * @param addr_type [in] Address type. - * @param addr_len [in] The length in bytes of the address data. For example, 4 for - * AT_IPv4 or sizeof(struct e_in6_addr) for AT_IPv6. - * @param tvb [in] Pointer to the TVB. - * @param offset [in] Offset within the TVB. - */ -static inline void -alloc_address_tvb(wmem_allocator_t *scope, address *addr, - int addr_type, int addr_len, tvbuff_t *tvb, int offset) { - const void *p; - - p = tvb_get_ptr(tvb, offset, addr_len); - alloc_address_wmem(scope, addr, addr_type, addr_len, p); -} - /** Compare two addresses. * * @param addr1 [in] The first address to compare. @@ -219,66 +163,56 @@ addresses_data_equal(const address *addr1, const address *addr2) { return FALSE; } -/** Perform a shallow copy of the address (both addresses point to the same - * memory location). +/** Copy an address, allocating a new buffer for the address data. * * @param to [in,out] The destination address. * @param from [in] The source address. - * - * \warning Make sure 'from' memory stays valid for the lifetime of this object. - * Also it's strongly recommended to use this function instead of copy-assign. */ static inline void -copy_address_shallow(address *to, const address *from) { - set_address(to, from->type, from->len, from->data); +copy_address(address *to, const address *from) { + guint8 *to_data; + + to->type = from->type; + to->len = from->len; + to_data = (guint8 *)g_malloc(from->len); + if (from->len != 0) + memcpy(to_data, from->data, from->len); + to->data = to_data; } -/** Copy an address, allocating a new buffer for the address data - * using wmem-scoped memory. +/** Perform a shallow copy of the address (both addresses point to the same + * memory location). * - * @param scope [in] The lifetime of the allocated memory, e.g., wmem_packet_scope() * @param to [in,out] The destination address. * @param from [in] The source address. */ static inline void -copy_address_wmem(wmem_allocator_t *scope, address *to, const address *from) { - alloc_address_wmem(scope, to, from->type, from->len, from->data); +copy_address_shallow(address *to, const address *from) { + memcpy(to, from, sizeof(address)); + /* + to->type = from->type; + to->len = from->len; + to->data = from->data; + */ } -/** Copy an address, allocating a new buffer for the address data. +/** Copy an address, allocating a new buffer for the address data + * using wmem-scoped memory. * + * @param scope [in] The lifetime of the allocated memory, wmem_packet_scope() * @param to [in,out] The destination address. * @param from [in] The source address. */ static inline void -copy_address(address *to, const address *from) { - copy_address_wmem(NULL, to, from); -} - -/** Free an address allocated with wmem-scoped memory. - * - * @param scope [in] The lifetime of the allocated memory, e.g., wmem_packet_scope() - * @param addr [in,out] The address whose data to free. - */ -static inline void -free_address_wmem(wmem_allocator_t *scope, address *addr) { - /* Because many dissectors set 'type = AT_NONE' to mean clear we check for that */ - if (addr->type != AT_NONE && addr->len > 0 && addr->priv != NULL) { - /* Make sure API use is correct */ - /* if priv is not null then data == priv */ - g_assert(addr->data == addr->priv); - wmem_free(scope, addr->priv); - } - clear_address(addr); -} - -/** Free an address. - * - * @param addr [in,out] The address whose data to free. - */ -static inline void -free_address(address *addr) { - free_address_wmem(NULL, addr); +copy_address_wmem(wmem_allocator_t *scope, address *to, const address *from) { + void *to_data; + + to->type = from->type; + to->len = from->len; + to_data = wmem_alloc(scope, from->len); + if (from->len != 0) + memcpy(to_data, from->data, from->len); + to->data = to_data; } /** Hash an address into a hash value (which must already have been set). |