From patchwork Wed Sep 28 08:51:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huajun li X-Patchwork-Id: 116722 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 071F2B6F72 for ; Wed, 28 Sep 2011 18:51:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753497Ab1I1Ivl (ORCPT ); Wed, 28 Sep 2011 04:51:41 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:48883 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750926Ab1I1Ivk (ORCPT ); Wed, 28 Sep 2011 04:51:40 -0400 Received: by fxe4 with SMTP id 4so330491fxe.19 for ; Wed, 28 Sep 2011 01:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=Q5HytwCYBM7AGt00S4Hzi8wObI2o9pWeGGPJTuD0MPM=; b=brCSo96lu/wRg6KxnP7EMpyrbEwYUxSUAPhXQgq8aYqB+qXyA/2PKj2iyG/se1OoBr ylotmmhV2aSH1lO0IgDdMaJPbTuNAWZZRDVDtEqbAJjYVdoFRX+qZW4azvAtlEXLMBpy 81hM3/pDnqVBwOSxK8IN0pjb4Obj86whhVhJE= MIME-Version: 1.0 Received: by 10.223.47.216 with SMTP id o24mr4626172faf.145.1317199899606; Wed, 28 Sep 2011 01:51:39 -0700 (PDT) Received: by 10.223.114.195 with HTTP; Wed, 28 Sep 2011 01:51:39 -0700 (PDT) Date: Wed, 28 Sep 2011 16:51:39 +0800 Message-ID: Subject: [PATCH v3] net/flow: Fix potential memory leak From: Huajun Li To: David Miller Cc: Eric Dumazet , netdev , Huajun Li Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org While preparing net flow caches, once a fail may cause potential memory leak , fix it. Signed-off-by: Huajun Li --- net/core/flow.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/net/core/flow.c b/net/core/flow.c index 555a456..8ae42de 100644 --- a/net/core/flow.c +++ b/net/core/flow.c @@ -413,7 +413,7 @@ static int __init flow_cache_init(struct flow_cache *fc) for_each_online_cpu(i) { if (flow_cache_cpu_prepare(fc, i)) - return -ENOMEM; + goto err; } fc->hotcpu_notifier = (struct notifier_block){ .notifier_call = flow_cache_cpu, @@ -426,6 +426,18 @@ static int __init flow_cache_init(struct flow_cache *fc) add_timer(&fc->rnd_timer); return 0; + +err: + for_each_possible_cpu(i) { + struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i); + kfree(fcp->hash_table); + fcp->hash_table = NULL; + } + + free_percpu(fc->percpu); + fc->percpu = NULL; + + return -ENOMEM; } static int __init flow_cache_init_global(void)