Skip to content

Commit

Permalink
Split a bunch of init routines into init() and cleanup(). This allows…
Browse files Browse the repository at this point in the history
… us to free memory properly on shutdown.

This is an initial step. There's still some work to do.

svn path=/trunk/; revision=29754
  • Loading branch information
krajaratnam committed Sep 6, 2009
1 parent d6122ad commit 0e5cef6
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 96 deletions.
16 changes: 12 additions & 4 deletions epan/circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ 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);

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)
{
/*
* Free up any space allocated for circuit protocol data
* areas.
Expand Down
1 change: 1 addition & 0 deletions epan/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct circuit {
circuit_key *key_ptr; /* pointer to the key for this circuit */
} circuit_t;

extern void circuit_cleanup(void);
extern void circuit_init(void);

extern circuit_t *circuit_new(circuit_type ctype, guint32 circuit_id,
Expand Down
19 changes: 15 additions & 4 deletions epan/conversation.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,10 @@ conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w)
}

/*
* Initialize some variables every time a file is loaded or re-loaded.
* Destroy all existing conversations, and create a new hash table
* for the conversations in the new file.
* Destroy all existing conversations
*/
void
conversation_init(void)
conversation_cleanup(void)
{
/* The conversation keys are se_ allocated so they are already gone */
conversation_keys = NULL;
Expand All @@ -427,6 +425,19 @@ conversation_init(void)
if (conversation_hashtable_no_addr2_or_port2 != NULL)
g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2);

conversation_hashtable_exact = NULL;
conversation_hashtable_no_addr2 = NULL;
conversation_hashtable_no_port2 = NULL;
conversation_hashtable_no_addr2_or_port2 = NULL;
}

/*
* Initialize some variables every time a file is loaded or re-loaded.
* Create a new hash table for the conversations in the new file.
*/
void
conversation_init(void)
{
/*
* Free up any space allocated for conversation protocol data
* areas.
Expand Down
1 change: 1 addition & 0 deletions epan/conversation.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef struct conversation {
conversation_key *key_ptr; /* pointer to the key for this conversation */
} conversation_t;

extern void conversation_cleanup(void);
extern void conversation_init(void);

extern conversation_t *conversation_new(guint32 setup_frame, address *addr1, address *addr2,
Expand Down
15 changes: 13 additions & 2 deletions epan/epan.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
void
epan_cleanup(void)
{
se_free_all();
expert_cleanup();
cleanup_dissection();
dfilter_cleanup();
proto_cleanup();
prefs_cleanup();
Expand All @@ -138,12 +137,24 @@ epan_conversation_init(void)
conversation_init();
}

void
epan_conversation_cleanup(void)
{
conversation_cleanup();
}

void
epan_circuit_init(void)
{
circuit_init();
}

void
epan_circuit_cleanup(void)
{
circuit_cleanup();
}

epan_dissect_t*
epan_dissect_init(epan_dissect_t *edt, gboolean create_proto_tree, gboolean proto_tree_visible)
{
Expand Down
2 changes: 2 additions & 0 deletions epan/epan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void epan_cleanup(void);
* value indicating to which flow the packet belongs.
*/
void epan_conversation_init(void);
void epan_conversation_cleanup(void);

/*
* Initialize the table of circuits. Circuits are identified by a
Expand All @@ -65,6 +66,7 @@ void epan_conversation_init(void);
* code.
*/
void epan_circuit_init(void);
void epan_circuit_cleanup(void);

/* A client will create one epan_t for an entire dissection session.
* A single epan_t will be used to analyze the entire sequence of packets,
Expand Down
10 changes: 4 additions & 6 deletions epan/expert.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,17 @@ const value_string expert_severity_vals[] = {
{ 0, NULL }
};



void
expert_init(void)
{
static hf_register_info hf[] = {
{ &hf_expert_msg,
{ "Message", "expert.message", FT_STRING, BASE_NONE, NULL, 0, "Wireshark expert information", HFILL }
},
{ &hf_expert_group,
{ &hf_expert_group,
{ "Group", "expert.group", FT_UINT32, BASE_NONE, VALS(expert_group_vals), 0, "Wireshark expert group", HFILL }
},
{ &hf_expert_severity,
{ &hf_expert_severity,
{ "Severity level", "expert.severity", FT_UINT32, BASE_NONE, VALS(expert_severity_vals), 0, "Wireshark expert severity level", HFILL }
}
};
Expand Down Expand Up @@ -118,7 +116,7 @@ expert_get_highest_severity(void)
}


/* set's the PI_ flags to a protocol item
/* set's the PI_ flags to a protocol item
* (and it's parent items till the toplevel) */
static void
expert_set_item_flags(proto_item *pi, int group, int severity)
Expand All @@ -138,7 +136,7 @@ expert_create_tree(proto_item *pi, int group, int severity, const char *msg)
proto_item *ti;

tree = proto_item_add_subtree(pi, ett_expert);
ti = proto_tree_add_protocol_format(tree, proto_expert, NULL, 0, 0, "Expert Info (%s/%s): %s",
ti = proto_tree_add_protocol_format(tree, proto_expert, NULL, 0, 0, "Expert Info (%s/%s): %s",
val_to_str(severity, expert_severity_vals, "?%u?"),
val_to_str(group, expert_group_vals, "?%u?"),
msg);
Expand Down
2 changes: 1 addition & 1 deletion epan/expert.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* expert.h
* Collecting of Expert information.
*
* For further info, see: http://wiki.wireshark.org/Development/ExpertInfo
* For further info, see: http://wiki.wireshark.org/Development/ExpertInfo
*
* $Id$
*
Expand Down
27 changes: 25 additions & 2 deletions epan/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ init_dissection(void)
/* Initialize the common data structures for fragment reassembly.
Must be done *after* calling init routines, as those routines
may free up space for fragments, which they find by using the
data structures that "reassemble_init()" frees. */
data structures that "reassemble_cleanup()" frees. */
reassemble_init();

/* Initialize the stream-handling tables */
Expand All @@ -155,7 +155,30 @@ init_dissection(void)
void
cleanup_dissection(void)
{
init_dissection();
/* Reclaim all memory of seasonal scope */
se_free_all();

/* Cleanup the table of conversations. */
epan_conversation_cleanup();

/* Cleanup the table of circuits. */
epan_circuit_cleanup();

/* TODO: Introduce cleanup_routines */
/* Cleanup protocol-specific variables. */
g_slist_foreach(init_routines, &call_init_routine, NULL);

/* Cleanup the common data structures for fragment reassembly.
Must be done *after* calling init routines, as those routines
may free up space for fragments, which they find by using the
data structures that "reassemble_cleanup()" frees. */
reassemble_cleanup();

/* Cleanup the stream-handling tables */
stream_cleanup();

/* Initialize the expert infos */
expert_cleanup();
}

/* Allow protocols to register a "cleanup" routine to be
Expand Down
22 changes: 16 additions & 6 deletions epan/reassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ reassembled_hash(gconstpointer k)
/*
* For a fragment hash table entry, free the address data to which the key
* refers and the fragment data to which the value refers.
* (The actual key and value structures get freed by "reassemble_init()".)
* (The actual key and value structures get freed by "reassemble_cleanup()".)
*/
static gboolean
free_all_fragments(gpointer key_arg, gpointer value, gpointer user_data _U_)
Expand Down Expand Up @@ -260,7 +260,7 @@ static fragment_data *new_head(guint32 flags)
/*
* For a reassembled-packet hash table entry, free the fragment data
* to which the value refers.
* (The actual value structures get freed by "reassemble_init()".)
* (The actual value structures get freed by "reassemble_cleanup()".)
*/
static gboolean
free_all_reassembled_fragments(gpointer key_arg _U_, gpointer value,
Expand Down Expand Up @@ -298,7 +298,7 @@ fragment_table_init(GHashTable **fragment_table)
*
* Remove all entries and free fragment data for
* each entry. (The key and value data is freed
* by "reassemble_init()".)
* by "reassemble_cleanup()".)
*/
g_hash_table_foreach_remove(*fragment_table,
free_all_fragments, NULL);
Expand All @@ -318,7 +318,7 @@ dcerpc_fragment_table_init(GHashTable **fragment_table)
*
* Remove all entries and free fragment data for
* each entry. (The key and value data is freed
* by "reassemble_init()".)
* by "reassemble_cleanup()".)
*/
g_hash_table_foreach_remove(*fragment_table,
free_all_fragments, NULL);
Expand All @@ -341,7 +341,7 @@ reassembled_table_init(GHashTable **reassembled_table)
*
* Remove all entries and free reassembled packet
* data for each entry. (The key data is freed
* by "reassemble_init()".)
* by "reassemble_cleanup()".)
*/
g_hash_table_foreach_remove(*reassembled_table,
free_all_reassembled_fragments, NULL);
Expand All @@ -357,7 +357,7 @@ reassembled_table_init(GHashTable **reassembled_table)
* reassembled keys.
*/
void
reassemble_init(void)
reassemble_cleanup(void)
{
#if GLIB_CHECK_VERSION(2,10,0)
#else
Expand All @@ -366,6 +366,16 @@ reassemble_init(void)
if (fragment_data_chunk != NULL)
g_mem_chunk_destroy(fragment_data_chunk);

fragment_key_chunk = NULL;
fragment_data_chunk = NULL;
#endif
}

void
reassemble_init(void)
{
#if GLIB_CHECK_VERSION(2,10,0)
#else
fragment_key_chunk = g_mem_chunk_new("fragment_key_chunk",
sizeof(fragment_key),
fragment_init_count * sizeof(fragment_key),
Expand Down
7 changes: 6 additions & 1 deletion epan/reassemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ extern void reassembled_table_init(GHashTable **reassembled_table);
/*
* Free up all space allocated for fragment keys and data.
*/
void reassemble_cleanup(void);

/*
* Initialise fragment keys and data.
*/
void reassemble_init(void);

/*
Expand Down Expand Up @@ -226,7 +231,7 @@ fragment_add_seq_next(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 id,
guint32 frag_data_len, gboolean more_frags);

extern void
fragment_start_seq_check(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
fragment_start_seq_check(packet_info *pinfo, guint32 id, GHashTable *fragment_table,
guint32 tot_len);

extern fragment_data *
Expand Down
Loading

0 comments on commit 0e5cef6

Please sign in to comment.