aboutsummaryrefslogtreecommitdiffstats
path: root/epan/stream.c
diff options
context:
space:
mode:
authorKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-06 18:25:23 +0000
committerKovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com>2009-09-06 18:25:23 +0000
commit0e5cef61be28b595269433c50b23ce71a24b9fd3 (patch)
tree3906bcb3782e7eeaccdf0142093b63c249a57593 /epan/stream.c
parentd6122ad4223c0616f3ac12b96f079f04cd83d3c4 (diff)
Split a bunch of init routines into init() and cleanup(). This allows us to free memory properly on shutdown.
This is an initial step. There's still some work to do. svn path=/trunk/; revision=29754
Diffstat (limited to 'epan/stream.c')
-rw-r--r--epan/stream.c91
1 files changed, 51 insertions, 40 deletions
diff --git a/epan/stream.c b/epan/stream.c
index 2122d0f49d..7bd0852dda 100644
--- a/epan/stream.c
+++ b/epan/stream.c
@@ -117,7 +117,7 @@ gboolean stream_compare_func(gconstpointer a,
if( key1 -> p2p_dir != key2 -> p2p_dir ||
key1-> is_circuit != key2 -> is_circuit )
return FALSE;
-
+
if( key1 -> is_circuit )
return (key1 -> circ.circuit == key2 -> circ.circuit );
else
@@ -133,23 +133,26 @@ static GMemChunk *streams = NULL;
static GHashTable *stream_hash;
-/* init/reset function, call from stream_init() */
-static void init_stream_hash( void ) {
- if( stream_hash != NULL ) {
- g_hash_table_destroy( stream_hash );
+/* cleanup reset function, call from stream_cleanup() */
+static void cleanup_stream_hash( void ) {
+ if( stream_hash != NULL ) {
+ g_hash_table_destroy( stream_hash );
stream_hash = NULL;
- }
+ }
- if( stream_keys != NULL ) {
- g_mem_chunk_destroy( stream_keys );
+ if( stream_keys != NULL ) {
+ g_mem_chunk_destroy( stream_keys );
stream_keys = NULL;
- }
+ }
- if( streams != NULL ) {
- g_mem_chunk_destroy( streams );
+ if( streams != NULL ) {
+ g_mem_chunk_destroy( streams );
streams = NULL;
- }
+ }
+}
+/* init function, call from stream_init() */
+static void init_stream_hash( void ) {
streams = g_mem_chunk_create(stream_t,
MEMCHUNK_STREAM_COUNT,
G_ALLOC_ONLY);
@@ -162,7 +165,6 @@ static void init_stream_hash( void ) {
stream_compare_func);
}
-
/* lookup function, returns null if not found */
static stream_t *stream_hash_lookup_circ( const struct circuit *circuit, int p2p_dir )
{
@@ -186,7 +188,7 @@ static stream_t *stream_hash_lookup_conv( const struct conversation *conv, int p
static stream_t *new_stream( stream_key_t *key )
{
stream_t *val;
-
+
val = g_mem_chunk_alloc(streams);
val -> key = key;
val -> pdu_counter = 0;
@@ -234,14 +236,16 @@ static GMemChunk *pdus = NULL;
/* pdu counter, for generating unique pdu ids */
static guint32 pdu_counter;
-
-static void stream_init_pdu_data(void)
+static void stream_cleanup_pdu_data(void)
{
if( pdus != NULL ) {
g_mem_chunk_destroy( pdus );
pdus = NULL;
}
+}
+static void stream_init_pdu_data(void)
+{
pdus = g_mem_chunk_create(stream_pdu_t,
MEMCHUNK_PDU_COUNT,
G_ALLOC_ONLY);
@@ -290,7 +294,7 @@ gboolean fragment_compare_func(gconstpointer a,
key1 -> framenum == key2 -> framenum &&
key1 -> offset == key2 -> offset );
}
-
+
/* memory pools */
static GMemChunk *fragment_keys = NULL;
static GMemChunk *fragment_vals = NULL;
@@ -299,27 +303,30 @@ static GMemChunk *fragment_vals = NULL;
static GHashTable *fragment_hash;
-/* init/reset function, call from stream_init() */
-static void init_fragment_hash( void ) {
- if( fragment_hash != NULL ) {
- g_hash_table_destroy( fragment_hash );
- fragment_hash = NULL;
- }
+/* cleanup function, call from stream_cleanup() */
+static void cleanup_fragment_hash( void ) {
+ if( fragment_hash != NULL ) {
+ g_hash_table_destroy( fragment_hash );
+ fragment_hash = NULL;
+ }
- if( fragment_vals != NULL ) {
- g_mem_chunk_destroy( fragment_vals );
- fragment_vals = NULL;
- }
+ if( fragment_vals != NULL ) {
+ g_mem_chunk_destroy( fragment_vals );
+ fragment_vals = NULL;
+ }
- if( fragment_keys != NULL ) {
- g_mem_chunk_destroy( fragment_keys );
- fragment_keys = NULL;
- }
+ if( fragment_keys != NULL ) {
+ g_mem_chunk_destroy( fragment_keys );
+ fragment_keys = NULL;
+ }
+}
+/* init function, call from stream_init() */
+static void init_fragment_hash( void ) {
fragment_keys = g_mem_chunk_create(fragment_key_t,
MEMCHUNK_FRAGMENT_COUNT,
G_ALLOC_ONLY);
-
+
fragment_vals = g_mem_chunk_create(stream_pdu_fragment_t,
MEMCHUNK_FRAGMENT_COUNT,
G_ALLOC_ONLY);
@@ -383,7 +390,7 @@ stream_t *stream_new_circ ( const struct circuit *circuit, int p2p_dir )
DISSECTOR_ASSERT( stream == NULL );
stream = stream_hash_insert_circ(circuit, p2p_dir);
-
+
return stream;
}
@@ -416,6 +423,13 @@ stream_t *find_stream_conv ( const struct conversation *conv, int p2p_dir )
return stream_hash_lookup_conv(conv,p2p_dir);
}
+/* cleanup the stream routines */
+void stream_cleanup( void )
+{
+ cleanup_stream_hash();
+ cleanup_fragment_hash();
+ stream_cleanup_pdu_data();
+}
/* initialise the stream routines */
void stream_init( void )
@@ -428,16 +442,13 @@ void stream_init( void )
reassembled_table_init(&stream_reassembled_table);
}
-
-
-
/*****************************************************************************/
stream_pdu_fragment_t *stream_find_frag( stream_t *stream, guint32 framenum, guint32 offset )
{
return fragment_hash_lookup( stream, framenum, offset );
}
-
+
stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guint32 offset,
tvbuff_t *tvb, packet_info *pinfo, gboolean more_frags )
{
@@ -457,7 +468,7 @@ stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guin
/* start a new pdu */
pdu = stream->current_pdu = stream_new_pdu(stream);
}
-
+
/* add it to the reassembly tables */
fd_head = fragment_add_seq_next(tvb, 0, pinfo, pdu->id,
stream_fragment_table, stream_reassembled_table,
@@ -470,7 +481,7 @@ stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guin
/* if this was the last fragment, update the pdu data.
*/
pdu -> fd_head = fd_head;
-
+
/* start a new pdu next time */
stream->current_pdu = NULL;
@@ -509,7 +520,7 @@ tvbuff_t *stream_process_reassembled(
return process_reassembled_data(tvb, offset, pinfo, name, pdu->fd_head,
fit, update_col_infop, tree);
}
-
+
guint32 stream_get_frag_length( const stream_pdu_fragment_t *frag)
{
DISSECTOR_ASSERT( frag );