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