[ovs-dev] [PATCH] ovn-trace: Fix memory leaks.
Ben Pfaff
blp at ovn.org
Fri Jan 13 19:28:54 UTC 2017
Suggested-by: Justin Pettit <jpettit at ovn.org>
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
ovn/utilities/ovn-trace.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
index 82b5ee6..b1ffe1f 100644
--- a/ovn/utilities/ovn-trace.c
+++ b/ovn/utilities/ovn-trace.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016 Nicira, Inc.
+ * Copyright (c) 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -856,11 +856,13 @@ struct ovntrace_node {
struct ovs_list node; /* In parent. */
enum ovntrace_node_type type;
- const char *name;
+ char *name;
bool always_indent;
struct ovs_list subs; /* List of children. */
};
+static void ovntrace_node_destroy(struct ovntrace_node *);
+
static struct ovntrace_node * OVS_PRINTF_FORMAT(3, 4)
ovntrace_node_append(struct ovs_list *super, enum ovntrace_node_type type,
const char *format, ...)
@@ -893,6 +895,29 @@ ovntrace_node_clone(const struct ovs_list *old, struct ovs_list *new)
}
static void
+ovntrace_node_list_destroy(struct ovs_list *list)
+{
+ if (list) {
+ struct ovntrace_node *node, *next;
+
+ LIST_FOR_EACH_SAFE (node, next, node, list) {
+ ovs_list_remove(&node->node);
+ ovntrace_node_destroy(node);
+ }
+ }
+}
+
+static void
+ovntrace_node_destroy(struct ovntrace_node *node)
+{
+ if (node) {
+ ovntrace_node_list_destroy(&node->subs);
+ free(node->name);
+ free(node);
+ }
+}
+
+static void
ovntrace_node_print_details(struct ds *output,
const struct ovs_list *nodes, int level)
{
@@ -928,8 +953,10 @@ ovntrace_node_prune_summary(struct ovs_list *nodes)
ovntrace_node_prune_summary(&sub->subs);
if (sub->type == OVNTRACE_NODE_MODIFY ||
sub->type == OVNTRACE_NODE_TABLE) {
+ /* Replace 'sub' by its children, if any, */
ovs_list_remove(&sub->node);
ovs_list_splice(&next->node, sub->subs.next, &sub->subs);
+ ovntrace_node_destroy(sub);
}
}
}
@@ -970,8 +997,10 @@ ovntrace_node_prune_hard(struct ovs_list *nodes)
sub->type == OVNTRACE_NODE_PIPELINE ||
sub->type == OVNTRACE_NODE_TABLE ||
sub->type == OVNTRACE_NODE_OUTPUT) {
+ /* Replace 'sub' by its children, if any, */
ovs_list_remove(&sub->node);
ovs_list_splice(&next->node, sub->subs.next, &sub->subs);
+ ovntrace_node_destroy(sub);
}
}
}
@@ -1569,6 +1598,7 @@ trace(const char *dp_s, const char *flow_s)
ovntrace_node_clone(&root, &clone);
ovntrace_node_prune_summary(&clone);
ovntrace_node_print_summary(&output, &clone, 0);
+ ovntrace_node_list_destroy(&clone);
}
if (minimal) {
@@ -1579,6 +1609,8 @@ trace(const char *dp_s, const char *flow_s)
ovntrace_node_print_summary(&output, &root, 0);
}
+ ovntrace_node_list_destroy(&root);
+
vconn_close(vconn);
return ds_steal_cstr(&output);
--
2.10.2
More information about the dev
mailing list