Received: by 10.213.65.68 with SMTP id h4csp1237644imn; Wed, 4 Apr 2018 15:22:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/8vTPq7RyitlZiqt2Bz2zCEa6nnJ9RKwbz4L/rHf7rO2fUBs50GxBpFpiDM6JrdtxogAbU X-Received: by 10.98.69.217 with SMTP id n86mr13315122pfi.41.1522880525559; Wed, 04 Apr 2018 15:22:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522880525; cv=none; d=google.com; s=arc-20160816; b=A3Pn8DUuIH7yxIaZu0KyL7LmVsxu3R6mOHQs2CsH3tH+idRabBZkSv1LCbB2dWVx9Z a/juKRoIuUVCKgQbapp8t3gXDcrUgE665NnMNBpNzgo8bqN0OKZ3o04XeLGvRWxqPnM7 UzAPVHU5UPNzpsiThTMP0QtumlrpocZmtU7sFCQcfq/zBX+UBCKdwSR3P7gDjb4eiElT nv2fxMr8Iw1pO1subPwWdYCwXVJuHrnSV0o2cJgs2DXyu9kC/x4XUPglMj+MpStyKOcI 9BvLYQWWsXoYVuSfNiHlyzeVJue1uAlaMgnWiqNN6QvgS2Kc7TCvqeQFSzC9QMLHbfpa 0G+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=zRlr8CeNo0TuBl2Vooffwwr7oZgplcWiSVulMHfdBYY=; b=KWLfwMWL++zlJG4jFkKld9Ig+AnCCgntjaXbv7KmD/iumPbkZ2+gqvNv4OnDFZjRZv 8A0EW2iyCLtpiplqsC9cL4AcRLd7gqjXcZ6oI/DAn1b4Dl1VdRVhbAdvKje1RbOxPsE7 BTanjqh2cfOLzWyHb8sx64HnAiuA4p8B4MAiWdnoMI0Yoa0mKCKqIGhFwI9gAiNwQHxM XDoQYe7/zkWlNnTZo3cj1VpcXZyaYiKJae1O05a4uqaSZvsHUEd4Ama9MsglhonGNXNi mLJLfJy5Ig65nyDwntLy6iAI6OxzIgcGmZra8t/x/sUufIAAU+JyX1H5QwlJADG6Uagu 0Ocg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v76si4864074pfa.96.2018.04.04.15.21.51; Wed, 04 Apr 2018 15:22:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752531AbeDDWUo (ORCPT + 99 others); Wed, 4 Apr 2018 18:20:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47792 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbeDDWUn (ORCPT ); Wed, 4 Apr 2018 18:20:43 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 37AEA11; Wed, 4 Apr 2018 22:20:41 +0000 (UTC) Date: Wed, 4 Apr 2018 15:20:39 -0700 From: Andrew Morton To: Xidong Wang Cc: Vitaly Wool , Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] z3fold: fix memory leak Message-Id: <20180404152039.aadbe5bbed5bc91da8c5fa99@linux-foundation.org> In-Reply-To: <1522803111-29209-1-git-send-email-wangxidong_97@163.com> References: <1522803111-29209-1-git-send-email-wangxidong_97@163.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 4 Apr 2018 08:51:51 +0800 Xidong Wang wrote: > In function z3fold_create_pool(), the memory allocated by > __alloc_percpu() is not released on the error path that pool->compact_wq > , which holds the return value of create_singlethread_workqueue(), is NULL. > This will result in a memory leak bug. > > ... > > --- a/mm/z3fold.c > +++ b/mm/z3fold.c > @@ -490,6 +490,7 @@ static struct z3fold_pool *z3fold_create_pool(const char *name, gfp_t gfp, > out_wq: > destroy_workqueue(pool->compact_wq); > out: > + free_percpu(pool->unbuddied); > kfree(pool); > return NULL; > } That isn't right. If the initial kzallc fails we'll goto out with pool==NULL. Please check: --- a/mm/z3fold.c~z3fold-fix-memory-leak-fix +++ a/mm/z3fold.c @@ -479,7 +479,7 @@ static struct z3fold_pool *z3fold_create pool->name = name; pool->compact_wq = create_singlethread_workqueue(pool->name); if (!pool->compact_wq) - goto out; + goto out_unbuddied; pool->release_wq = create_singlethread_workqueue(pool->name); if (!pool->release_wq) goto out_wq; @@ -489,9 +489,10 @@ static struct z3fold_pool *z3fold_create out_wq: destroy_workqueue(pool->compact_wq); -out: +out_unbuddied: free_percpu(pool->unbuddied); kfree(pool); +out: return NULL; } _