From Jakub Zawadzki via bug #4289: (Fix for) Frame arrival times (pcap)
[obnox/wireshark/wip.git] / epan / circuit.c
index f4fb47ee85fa1c9f81b48d60ac70406e23827adb..16ba7322540d9911d7f8066c56598c31536610f0 100644 (file)
@@ -3,8 +3,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 # include "config.h"
 #endif
 
-#include <stdio.h>
-
-#include <string.h>
 #include <glib.h>
 #include "packet.h"
 #include "circuit.h"
+#include "emem.h"
 
 /*
  * Hash table for circuits.
  */
 static GHashTable *circuit_hashtable = NULL;
 
-static GMemChunk *circuit_key_chunk = NULL;
-static GMemChunk *circuit_chunk = NULL;
-
 static guint32 new_index;
 
-static int circuit_init_count = 200;
-
 /*
  * Protocol-specific data attached to a circuit_t structure - protocol
  * index and opaque pointer.
@@ -54,8 +47,6 @@ typedef struct _circuit_proto_data {
        void    *proto_data;
 } circuit_proto_data;
 
-static GMemChunk *circuit_proto_data_area = NULL;
-
 /*
  * Compute the hash value for a circuit.
  */
@@ -80,47 +71,34 @@ circuit_match(gconstpointer v, gconstpointer w)
 }
 
 /*
- * Initialize some variables every time a file is loaded or re-loaded.
- * Destroy all existing circuits, and create a new hash table
- * for the circuits in the new file.
+ * Destroy all existing circuits.
  */
 void
-circuit_init(void)
+circuit_cleanup(void)
 {
-       if (circuit_hashtable != NULL)
-               g_hash_table_destroy(circuit_hashtable);
-       if (circuit_key_chunk != NULL)
-               g_mem_chunk_destroy(circuit_key_chunk);
-       if (circuit_chunk != NULL)
-               g_mem_chunk_destroy(circuit_chunk);
-
        /*
-        * Free up any space allocated for circuit protocol data
-        * areas.
+        * Free up any space allocated for the circuit hashtable.
         *
-        * We can free the space, as the structures it contains are
-        * pointed to by circuit data structures that were freed
-        * above.
+        * We can free the hash as the structures pointed to in the
+         * hash are in "seasonal" memory which is freed separately.
+         * Note: circuit_cleanup() must be called only when
+         *       seasonal memory is also freed.
         */
-       if (circuit_proto_data_area != NULL)
-               g_mem_chunk_destroy(circuit_proto_data_area);
 
-       circuit_hashtable = g_hash_table_new(circuit_hash, circuit_match);
-       circuit_key_chunk = g_mem_chunk_new("circuit_key_chunk",
-           sizeof(circuit_key),
-           circuit_init_count * sizeof(struct circuit_key),
-           G_ALLOC_AND_FREE);
-       circuit_chunk = g_mem_chunk_new("circuit_chunk",
-           sizeof(circuit_t),
-           circuit_init_count * sizeof(circuit_t),
-           G_ALLOC_AND_FREE);
+       if (circuit_hashtable != NULL)
+               g_hash_table_destroy(circuit_hashtable);
 
-       /*
-        * Allocate a new area for circuit protocol data items.
-        */
-       circuit_proto_data_area = g_mem_chunk_new("circuit_proto_data_area",
-           sizeof(circuit_proto_data), 20 * sizeof(circuit_proto_data), /* FIXME*/
-           G_ALLOC_ONLY);
+       circuit_hashtable = NULL;
+}
+
+/*
+ * Initialize some variables every time a file is loaded or re-loaded.
+ * Create a new hash table for the circuits in the new file.
+ */
+void
+circuit_init(void)
+{
+       circuit_hashtable = g_hash_table_new(circuit_hash, circuit_match);
 
        /*
         * Start the circuit indices over at 0.
@@ -138,11 +116,11 @@ circuit_new(circuit_type ctype, guint32 circuit_id, guint32 first_frame)
        circuit_t *circuit, *old_circuit;
        circuit_key *new_key;
 
-       new_key = g_mem_chunk_alloc(circuit_key_chunk);
+       new_key = se_alloc(sizeof(struct circuit_key));
        new_key->ctype = ctype;
        new_key->circuit_id = circuit_id;
 
-       circuit = g_mem_chunk_alloc(circuit_chunk);
+       circuit = se_alloc(sizeof(circuit_t));
        circuit->next = NULL;
        circuit->first_frame = first_frame;
        circuit->last_frame = 0;        /* not known yet */
@@ -205,7 +183,7 @@ find_circuit(circuit_type ctype, guint32 circuit_id, guint32 frame)
        for (circuit = g_hash_table_lookup(circuit_hashtable, &key);
            circuit != NULL; circuit = circuit->next) {
                /*
-                * The frame includes that frame number if:
+                * The circuit includes that frame number if:
                 *
                 *      the circuit's first frame is unknown or is at or
                 *      before that frame
@@ -250,7 +228,7 @@ p_compare(gconstpointer a, gconstpointer b)
 void
 circuit_add_proto_data(circuit_t *conv, int proto, void *proto_data)
 {
-       circuit_proto_data *p1 = g_mem_chunk_alloc(circuit_proto_data_area);
+       circuit_proto_data *p1 = se_alloc(sizeof(circuit_proto_data));
 
        p1->proto = proto;
        p1->proto_data = proto_data;
@@ -316,7 +294,7 @@ circuit_get_dissector(circuit_t *circuit)
  */
 gboolean
 try_circuit_dissector(circuit_type ctype, guint32 circuit_id, guint32 frame,
-    tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+                     tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        circuit_t *circuit;