Optimize proto_tree_print_node() + fix possible memleak when -O is used

svn path=/trunk/; revision=50699
This commit is contained in:
Jakub Zawadzki 2013-07-17 17:16:22 +00:00
parent 30d5ffbe79
commit 3845249a7f
1 changed files with 10 additions and 13 deletions

View File

@ -157,8 +157,8 @@ proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
#define MAX_INDENT 160
/* Print a tree's data, and any child nodes. */
static
void proto_tree_print_node(proto_node *node, gpointer data)
static void
proto_tree_print_node(proto_node *node, gpointer data)
{
field_info *fi = PNODE_FINFO(node);
print_data *pdata = (print_data*) data;
@ -186,14 +186,16 @@ void proto_tree_print_node(proto_node *node, gpointer data)
proto_item_fill_label(fi, label_str);
}
if (PROTO_ITEM_IS_GENERATED(node)) {
label_ptr = g_strdup_printf("[%s]", label_ptr);
}
if (PROTO_ITEM_IS_GENERATED(node))
label_ptr = g_strconcat("[", label_ptr, "]", NULL);
if (!print_line(pdata->stream, pdata->level, label_ptr)) {
pdata->success = FALSE;
pdata->success = print_line(pdata->stream, pdata->level, label_ptr);
if (PROTO_ITEM_IS_GENERATED(node))
g_free(label_ptr);
if (!pdata->success)
return;
}
/*
* If -O is specified, only display the protocols which are in the
@ -204,14 +206,9 @@ void proto_tree_print_node(proto_node *node, gpointer data)
*/
if ((output_only_tables != NULL) && (pdata->level == 0)
&& (g_hash_table_lookup(output_only_tables, fi->hfinfo->abbrev) == NULL)) {
pdata->success = TRUE;
return;
}
if (PROTO_ITEM_IS_GENERATED(node)) {
g_free(label_ptr);
}
/* If it's uninterpreted data, dump it (unless our caller will
be printing the entire packet in hex). */
if ((fi->hfinfo->id == proto_data) && (pdata->print_hex_for_data)) {