Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751816AbdHVPvP (ORCPT ); Tue, 22 Aug 2017 11:51:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53454 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbdHVPvN (ORCPT ); Tue, 22 Aug 2017 11:51:13 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3388E13A9B Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH] fix memory leak on kvm_vm_ioctl_get_htab_fd To: nixiaoming , agraf@suse.com, rkrcmar@redhat.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20170822141820.67839-1-nixiaoming@huawei.com> From: Paolo Bonzini Message-ID: Date: Tue, 22 Aug 2017 17:51:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170822141820.67839-1-nixiaoming@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 22 Aug 2017 15:51:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 907 Lines: 25 On 22/08/2017 16:18, nixiaoming wrote: > ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); > but no free when anon_inode_getfd return fail > so, add kfree(ctx) to fix memory leak > > Signed-off-by: nixiaoming > --- > arch/powerpc/kvm/book3s_64_mmu_hv.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c > index b42812e..be3d08f 100644 > --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c > +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c > @@ -1940,6 +1940,7 @@ int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *ghf) > rwflag = (ghf->flags & KVM_GET_HTAB_WRITE) ? O_WRONLY : O_RDONLY; > ret = anon_inode_getfd("kvm-htab", &kvm_htab_fops, ctx, rwflag | O_CLOEXEC); > if (ret < 0) { > + kfree(ctx); > kvm_put_kvm(kvm); > return ret; > } > Reviewed-by: Paolo Bonzini