From patchwork Fri Jan 13 19:28:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 715225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v0XkG23d6z9t2g for ; Sat, 14 Jan 2017 06:29:10 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 017059B9; Fri, 13 Jan 2017 19:29:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 4B656904 for ; Fri, 13 Jan 2017 19:29:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B752B1C0 for ; Fri, 13 Jan 2017 19:29:04 +0000 (UTC) Received: from mfilter42-d.gandi.net (mfilter42-d.gandi.net [217.70.178.172]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 97A4EFB883; Fri, 13 Jan 2017 20:29:03 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter42-d.gandi.net Received: from relay6-d.mail.gandi.net ([IPv6:::ffff:217.70.183.198]) by mfilter42-d.gandi.net (mfilter42-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id C3wi_phNE2AO; Fri, 13 Jan 2017 20:29:02 +0100 (CET) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id D22A3FB87E; Fri, 13 Jan 2017 20:29:00 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Fri, 13 Jan 2017 11:28:54 -0800 Message-Id: <20170113192854.29718-1-blp@ovn.org> X-Mailer: git-send-email 2.10.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] ovn-trace: Fix memory leaks. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Suggested-by: Justin Pettit Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- 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);