hmm
authorsahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 22 Dec 2006 09:01:12 +0000 (09:01 +0000)
committersahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 22 Dec 2006 09:01:12 +0000 (09:01 +0000)
best to revert this for a while.

revert all changes from previous patch.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@20195 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dfilter/dfvm.c
epan/ftypes/ftype-ipv4.c
epan/ftypes/ftype-string.c
epan/ftypes/ftypes.c
epan/ftypes/ftypes.h
epan/libwireshark.def
epan/proto.c
gtk/dfilter_expr_dlg.c

index d3db1121ac3a3f85f02acfb189fcdfae5323c15b..9d368abb1874b087305d5a3e0fd4aec73cbffa4b 100644 (file)
@@ -44,6 +44,7 @@ dfvm_value_free(dfvm_value_t *v)
 {
        switch (v->type) {
                case FVALUE:
+                       FVALUE_FREE(v->value.fvalue);
                        break;
                case DRANGE:
                        drange_free(v->value.drange);
index 6a17e528fa2a1c71c24074e7c4810fc6d4b6d276..045c9fbf104972befc339c533f46e1c0ceac19c9 100644 (file)
@@ -105,6 +105,7 @@ val_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFu
                        return FALSE;
                }
                nmask_bits = fvalue_get_integer(nmask_fvalue);
+               FVALUE_FREE(nmask_fvalue);
 
                if (nmask_bits > 32) {
                        logfunc("Netmask bits in a CIDR IPv4 address should be <= 32, not %u",
index b156cb1d608713eccfc424ea046f138212b8ba2b..b24086363c3c523b99504f69aab6b5515e0ccc66 100644 (file)
@@ -178,6 +178,7 @@ val_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFu
                memcpy(fv->value.string, fv_bytes->value.bytes->data, num_bytes);
                fv->value.string[num_bytes] = '\0';
 
+               FVALUE_FREE(fv_bytes);
                return TRUE;
        }
        else {
index a096f7a9d2ca5cf73c0a3d5cad11db7905122828..a2305f97f9fdbf8ce84545408c38e09ee257b785 100644 (file)
@@ -27,7 +27,6 @@
 #include <ftypes-int.h>
 #include <glib.h>
 #include "../slab.h"
-#include "../emem.h"
 
 #include "ftypes.h"
 
@@ -204,7 +203,7 @@ fvalue_new(ftenum_t ftype)
        ftype_t                 *ft;
        FvalueNewFunc           new_value;
 
-       fv=ep_alloc(sizeof(fvalue_t));
+       SLAB_ALLOC(fv, fvalue_t);
 
        FTYPE_LOOKUP(ftype, ft);
        fv->ftype = ft;
@@ -247,6 +246,7 @@ fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogF
                logfunc("\"%s\" cannot be converted to %s.",
                                s, ftype_pretty_name(ftype));
        }
+       FVALUE_FREE(fv);
        return NULL;
 }
 
@@ -265,6 +265,7 @@ fvalue_from_string(ftenum_t ftype, char *s, LogFunc logfunc)
                logfunc("\"%s\" cannot be converted to %s.",
                                s, ftype_pretty_name(ftype));
        }
+       FVALUE_FREE(fv);
        return NULL;
 }
 
index 145c3bc272bea3e73787fd3489e6c3fb1b6b2a10..6e42655693f1b590882e0ccbc24bc736ae356950 100644 (file)
@@ -241,6 +241,31 @@ void
 fvalue_init(fvalue_t *fv, ftenum_t ftype);
 
 
+/* Define type needed for the fvalue_t free list. */
+SLAB_ITEM_TYPE_DEFINE(fvalue_t)
+
+/* Free all memory used by an fvalue_t. With MSVC and a 
+ * libwireshark.dll, we need a special declaration.
+ */
+WS_VAR_IMPORT SLAB_FREE_LIST_DECLARE(fvalue_t)
+
+
+#define FVALUE_CLEANUP(fv)                                     \
+       {                                                       \
+               register FvalueFreeFunc free_value;             \
+               free_value = (fv)->ftype->free_value;   \
+               if (free_value) {                               \
+                       free_value((fv));                       \
+               }                                               \
+       }
+
+#define FVALUE_FREE(fv)                                                \
+       {                                                       \
+               FVALUE_CLEANUP(fv)                              \
+               SLAB_FREE(fv, fvalue_t);                        \
+       }
+
+
 fvalue_t*
 fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogFunc logfunc);
 
index 62b31da062d3f2d998a89169b67e726a0b8abf51..1d0f340c919665d26d943ff38a58c4b5e402c99c 100644 (file)
@@ -322,6 +322,7 @@ ftype_can_matches
 ftype_can_ne
 ftype_can_slice
 ftype_pretty_name
+fvalue_t_free_list              DATA
 fvalue_from_unparsed
 fvalue_get
 fvalue_get_floating
index f4bc266acb3ead0893bd00123bdf39e46b3bfe0a..1cbcb19aac2eaccab3bf57a9a3b6868140d29e3d 100644 (file)
@@ -203,6 +203,17 @@ static GList *protocols = NULL;
  * dissectors register their data */
 static GMemChunk *gmc_hfinfo = NULL;
 
+/* Contains information about a field when a dissector calls
+ * proto_tree_add_item.  */
+SLAB_ITEM_TYPE_DEFINE(field_info)
+static SLAB_FREE_LIST_DEFINE(field_info)
+static field_info *field_info_tmp=NULL;
+#define FIELD_INFO_NEW(fi)                                     \
+       SLAB_ALLOC(fi, field_info)
+#define FIELD_INFO_FREE(fi)                                    \
+       SLAB_FREE(fi, field_info)
+
+
 
 /* Contains the space for proto_nodes. */
 SLAB_ITEM_TYPE_DEFINE(proto_node)
@@ -218,6 +229,15 @@ static SLAB_FREE_LIST_DEFINE(proto_node)
 
 
 
+/* String space for protocol and field items for the GUI */
+SLAB_ITEM_TYPE_DEFINE(item_label_t)
+static SLAB_FREE_LIST_DEFINE(item_label_t)
+#define ITEM_LABEL_NEW(il)                             \
+       SLAB_ALLOC(il, item_label_t)
+#define ITEM_LABEL_FREE(il)                            \
+       SLAB_FREE(il, item_label_t)
+
+
 #define PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo) \
        DISSECTOR_ASSERT((guint)hfindex < gpa_hfinfo.len); \
        hfinfo=gpa_hfinfo.hfi[hfindex];
@@ -496,6 +516,13 @@ free_node_tree_data(tree_data_t *tree_data)
         g_free(tree_data);
 }
 
+#define FREE_NODE_FIELD_INFO(finfo)    \
+       if(finfo->rep){                 \
+               ITEM_LABEL_FREE(finfo->rep);    \
+       }                               \
+       FVALUE_CLEANUP(&finfo->value);  \
+       FIELD_INFO_FREE(finfo);
+
 static gboolean
 proto_tree_free_node(proto_node *node, gpointer data _U_)
 {
@@ -506,6 +533,11 @@ proto_tree_free_node(proto_node *node, gpointer data _U_)
                 * There is no field_info to destroy. */
                free_node_tree_data(PTREE_DATA(node));
        }
+       else {
+               /* This is a child node. Don't free the per-tree data, but
+                * do free the field_info data. */
+               FREE_NODE_FIELD_INFO(finfo);
+       }
 
        /* Free the proto_node. */
        PROTO_NODE_FREE(node);
@@ -773,6 +805,28 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, int hfindex,
        GHashTable      *hash;
        GPtrArray       *ptrs;
 
+       /* there is a possibility here that we might raise an exception
+        * and thus would lose track of the field_info.
+        * store it in a temp so that if we come here again we can reclaim
+        * the field_info without leaking memory.
+        */
+       /* XXX this only keeps track of one field_info struct,
+          if we ever go multithreaded for calls to this function
+          we have to change this code to use per thread variable.
+       */
+       if(field_info_tmp){
+               /* oops, last one we got must have been lost due
+                * to an exception.
+                * good thing we saved it, now we can reverse the
+                * memory leak and reclaim it.
+                */
+               SLAB_FREE(field_info_tmp, field_info);
+       }
+       /* we might throw an exception, keep track of this one
+        * across the "dangerous" section below.
+       */
+       field_info_tmp=new_fi;
+
        switch(new_fi->hfinfo->type) {
                case FT_NONE:
                        /* no value to set for FT_NONE */
@@ -971,6 +1025,11 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, int hfindex,
         * raised by a tvbuff access method doesn't leave junk in the proto_tree. */
        pi = proto_tree_add_node(tree, new_fi);
 
+       /* we did not raise an exception so we dont have to remember this
+        * field_info struct any more.
+        */
+       field_info_tmp=NULL;
+
        /* If the proto_tree wants to keep a record of this finfo
         * for quick lookup, then record it. */
        if (new_fi->hfinfo->ref_count) {
@@ -2817,7 +2876,7 @@ new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
 {
        field_info              *fi;
 
-       fi=ep_alloc(sizeof(field_info));
+       FIELD_INFO_NEW(fi);
 
        fi->hfinfo = hfinfo;
        fi->start = start;
@@ -2859,7 +2918,7 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list
        field_info *fi = PITEM_FINFO(pi);
 
        if (!PROTO_ITEM_IS_HIDDEN(pi)) {
-               fi->rep=ep_alloc(sizeof(item_label_t));
+               ITEM_LABEL_NEW(fi->rep);
                replen = 0;
                ret = g_snprintf(fi->rep->representation, ITEM_LABEL_LENGTH,
                    "%s: ", fi->hfinfo->name);
@@ -2886,7 +2945,7 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
        field_info *fi = PITEM_FINFO(pi);
 
        if (!PROTO_ITEM_IS_HIDDEN(pi)) {
-               fi->rep=ep_alloc(sizeof(item_label_t));
+               ITEM_LABEL_NEW(fi->rep);
                ret = g_vsnprintf(fi->rep->representation, ITEM_LABEL_LENGTH, format, ap);
                if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
                        fi->rep->representation[ITEM_LABEL_LENGTH - 1] = '\0';
@@ -2906,6 +2965,10 @@ proto_item_set_text(proto_item *pi, const char *format, ...)
 
        fi = PITEM_FINFO(pi);
 
+       if(fi->rep){
+               ITEM_LABEL_FREE(fi->rep);
+       }
+
        va_start(ap, format);
        proto_tree_set_representation(pi, format, ap);
        va_end(ap);
@@ -2934,7 +2997,7 @@ proto_item_append_text(proto_item *pi, const char *format, ...)
                 * generate the default representation.
                 */
                if (fi->rep == NULL) {
-                       fi->rep=ep_alloc(sizeof(item_label_t));
+                       ITEM_LABEL_NEW(fi->rep);
                        proto_item_fill_label(fi, fi->rep->representation);
                }
 
index 875944a7dc32fa06924097b2142c7e99493c09f7..1eccd111f7d5b62b83c6b41f568b6740dbd627ce 100644 (file)
@@ -920,6 +920,7 @@ dfilter_expr_dlg_accept_cb(GtkWidget *w, gpointer filter_te_arg)
             g_free(value_str);
             return;
         }
+        FVALUE_FREE(fvalue);
     } else {
         value_str = NULL;
         stripped_value_str = NULL;