aboutsummaryrefslogtreecommitdiffstats
path: root/epan/print.c
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-17 17:16:22 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-17 17:16:22 +0000
commit3845249a7f59b2337a13de77b8a9e51cbc398d08 (patch)
tree219ba408cd8ab662d5a526bea44fd8798d00da0c /epan/print.c
parent30d5ffbe79c4cec2ab5b72d51bd7c9f8962c2bb2 (diff)
Optimize proto_tree_print_node() + fix possible memleak when -O is used
svn path=/trunk/; revision=50699
Diffstat (limited to 'epan/print.c')
-rw-r--r--epan/print.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/epan/print.c b/epan/print.c
index 41fd7d9b17..25f89b1353 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -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);
+
+ pdata->success = print_line(pdata->stream, pdata->level, label_ptr);
+
+ if (PROTO_ITEM_IS_GENERATED(node))
+ g_free(label_ptr);
- if (!print_line(pdata->stream, pdata->level, label_ptr)) {
- pdata->success = FALSE;
+ 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)) {