From patchwork Fri Feb 20 18:49:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Mayhew X-Patchwork-Id: 5858211 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 87258BF440 for ; Fri, 20 Feb 2015 18:49:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8192204B5 for ; Fri, 20 Feb 2015 18:49:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3F9A2012E for ; Fri, 20 Feb 2015 18:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753863AbbBTSt3 (ORCPT ); Fri, 20 Feb 2015 13:49:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34979 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753570AbbBTSt3 (ORCPT ); Fri, 20 Feb 2015 13:49:29 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1KInSnw016321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 20 Feb 2015 13:49:28 -0500 Received: from tonberry.usersys.redhat.com (dhcp145-188.rdu.redhat.com [10.13.145.188]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1KInSL5022078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 20 Feb 2015 13:49:28 -0500 Received: from tonberry.usersys.redhat.com (localhost [127.0.0.1]) by tonberry.usersys.redhat.com (8.14.8/8.14.5) with ESMTP id t1KInSU6058359; Fri, 20 Feb 2015 13:49:28 -0500 Received: (from smayhew@localhost) by tonberry.usersys.redhat.com (8.14.8/8.14.8/Submit) id t1KInSHl058358; Fri, 20 Feb 2015 13:49:28 -0500 From: Scott Mayhew To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [nfs-utils PATCH] mountd: Fix memory leak in getexportent Date: Fri, 20 Feb 2015 13:49:27 -0500 Message-Id: <1424458167-58324-1-git-send-email-smayhew@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Valgrind shows that the memory allocated for ee.e_hostname in getexportent() is being leaked. While there _is_ a call to xfree(), by the time it gets called the leak's already happened. Moving the xfree() call so that it occurs before the assignment that overwrites ee fixes this. Signed-off-by: Scott Mayhew --- support/nfs/exports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/nfs/exports.c b/support/nfs/exports.c index eb782b9..4b17d3c 100644 --- a/support/nfs/exports.c +++ b/support/nfs/exports.c @@ -154,6 +154,7 @@ getexportent(int fromkernel, int fromexports) } } + xfree(ee.e_hostname); ee = def_ee; /* Check for default client */ @@ -176,7 +177,6 @@ getexportent(int fromkernel, int fromexports) if (!has_default_opts) xlog(L_WARNING, "No options for %s %s: suggest %s(sync) to avoid warning", ee.e_path, exp, exp); } - xfree(ee.e_hostname); ee.e_hostname = xstrdup(hostname); if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)