From patchwork Tue Mar 15 03:07:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piyush Pangtey X-Patchwork-Id: 597350 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qPKKx6YMWz9sds for ; Tue, 15 Mar 2016 14:07:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=wZ/svZMl; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932931AbcCODHc (ORCPT ); Mon, 14 Mar 2016 23:07:32 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33160 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbcCODHb (ORCPT ); Mon, 14 Mar 2016 23:07:31 -0400 Received: by mail-pf0-f196.google.com with SMTP id x3so754497pfb.0 for ; Mon, 14 Mar 2016 20:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=bIeqBDUazuktj5srTuWv9GDTU1X8swO6n+5DeSvD7L4=; b=wZ/svZMlTG0gCyCEhizD1WEB9HK+LkrgTUAHitwplJGGD0nKU/7tRkT/oWBgVjxbfL rb1X1b19v849h6Y7tO/E08AkAjuYUFI1rkFBS9Ty7Eq9uRqiGD2TazP+yuvlchrHO23s 11amERGcNVlQz454UJcJap/7Jd6cTLZ23i06HaO8aL0nGJwKbQbDhPHM+jRwMMNdya5o 7VVsOklXM3oxBJyuZ7NELnSSY1dxBygpXGhJpa1aOADWgI5LDWDeC+i1Cp3xjPD62naw 5tHqHc3SrQl0+S6o61pt1HPJ4OGHovXgZzLylDlB+yz3hgl3yBuZ91lSF6cOJdW9OSMe 1YKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=bIeqBDUazuktj5srTuWv9GDTU1X8swO6n+5DeSvD7L4=; b=eBGnMHo6QqRkjj4MA1hvXwQwKPdnwwV3DOConJxjZ9BT5Hbq3I9ESr6zsHJO8CHDe9 +AY4y7d982d6I78RkeXgw7Lg09XsDxs9WADS16SJXmlfqEEo2aI/BwqlxbRcu4Lx53EL /rYn066GEfIBaGHlk9Bt7liyhsUnUbxotfQU0axcYvvKEUfRX/91J2n8G2WLGpGv+wH8 r1DKqWXTRN4ozWX43ro4pysce5hTc9lt16KgGlMkpyEm8VKlapA3vml4KSgeJE0rfxeI cHcaII8/2TvbYADh4atLnsG8fbYOIEcdzqUl4CXi9PETHnW0tZT4WenTz3m7HZkIAtBr 3Qdg== X-Gm-Message-State: AD7BkJJVxQGdPlp3aIYDtqI/1eHyROvZ/9l0MlGuz7myJUNQqUpZZGIylLJTzXd3/eN61w== X-Received: by 10.66.191.202 with SMTP id ha10mr43250916pac.8.1458011250867; Mon, 14 Mar 2016 20:07:30 -0700 (PDT) Received: from fate ([117.255.60.200]) by smtp.gmail.com with ESMTPSA id s66sm262521pfi.3.2016.03.14.20.07.28 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 14 Mar 2016 20:07:30 -0700 (PDT) Date: Tue, 15 Mar 2016 08:37:41 +0530 From: Piyush Pangtey To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org Subject: [PATCH v2] nft: Remove memory-leak Message-ID: <20160315030741.GA3900@fate> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Added matching xfree calls in chain_free(), for the chain members 'type' and 'dev'. It can be reproduced by : $ nft $ nft -i For example : $ sudo valgrind --leak-check=full nft list tables ==2899== HEAP SUMMARY: ==2899== in use at exit: 327 bytes in 10 blocks ==2899== total heap usage: 145 allocs, 135 frees, 211,462 bytes allocated ==2899== ==2899== 63 bytes in 9 blocks are definitely lost in loss record 1 of 2 ==2899== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==2899== by 0x57A3839: strdup (strdup.c:42) ==2899== by 0x41C05D: xstrdup (utils.c:64) ==2899== by 0x411E9B: netlink_delinearize_chain.isra.3 (netlink.c:717) ==2899== by 0x411F70: list_chain_cb (netlink.c:748) ==2899== by 0x504A943: nft_chain_list_foreach (chain.c:1015) ==2899== by 0x4145AE: netlink_list_chains (netlink.c:771) ==2899== by 0x40793F: cache_init_objects (rule.c:90) ==2899== by 0x40793F: cache_init (rule.c:130) ==2899== by 0x40793F: cache_update (rule.c:147) ==2899== by 0x40FB59: cmd_evaluate (evaluate.c:2475) ==2899== by 0x429A1C: nft_parse (parser_bison.y:655) ==2899== by 0x40651C: nft_run (main.c:231) ==2899== by 0x40618C: main (main.c:357) ==2899== ==2899== LEAK SUMMARY: ==2899== definitely lost: 63 bytes in 9 blocks ==2899== indirectly lost: 0 bytes in 0 blocks ==2899== possibly lost: 0 bytes in 0 blocks ==2899== still reachable: 264 bytes in 1 blocks ==2899== suppressed: 0 bytes in 0 blocks ==2899== Reachable blocks (those to which a pointer was found) are not shown. ==2899== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==2899== ==2899== For counts of detected and suppressed errors, rerun with: -v ==2899== Use --track-origins=yes to see where uninitialised values come from ==2899== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0) Signed-off-by: Piyush Pangtey --- v2: - Added valgrind output, as suggested by Pablo Neira Ayuso. src/rule.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rule.c b/src/rule.c index 0b78549..85987b9 100644 --- a/src/rule.c +++ b/src/rule.c @@ -510,6 +510,9 @@ void chain_free(struct chain *chain) rule_free(rule); handle_free(&chain->handle); scope_release(&chain->scope); + xfree(chain->type); + if (chain->dev != NULL) + xfree(chain->dev); xfree(chain); }