Received: by 10.223.185.116 with SMTP id b49csp1196974wrg; Wed, 21 Feb 2018 13:58:39 -0800 (PST) X-Google-Smtp-Source: AH8x2247gpnPD1CSYYNY1jXdYA6MoTn4Hgue6+aSLaLAiNqf94er6UXDC5xdapbMb59SL+YyeYj9 X-Received: by 2002:a17:902:bd94:: with SMTP id q20-v6mr4410551pls.247.1519250319664; Wed, 21 Feb 2018 13:58:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519250319; cv=none; d=google.com; s=arc-20160816; b=atOjTtMJUH19Wr2M553GmMAyuLdAPphCvbsO+rdbyV9K8BpfkQ04IRyglSFAc+zuW4 Cy/geZ2R9sDWYO9cUHMTQMc/r0+aDw2f4F2outgX0IIdoxpbB8euFtzkM9pDxqxs0G8j VhXcQjKMFRhzAtVd0L31poaXnevVna598Ookm0f+nCJwiStZCJCaLm8ksu6rCSYn3uGh Azjrv+1miEDu+VbktwiEW/MhP8uvSeB14HMf6boUHrM+PYhND9OW8Ct23thgd+eOi7Vi USigvrEtJwybAYc/PTz3eZo2g2j7oTuUXtHQaVWugB7b4N9uffNw1KO8cnI/Ipr2aC7y JI7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=0rQffMA5Qj33001k3S9wjN/6Sk2urrIoV681jPvgFAI=; b=oOWFrcv7fS/T87ZD8gNKqtNi7PCSYIreBaovMmfwEkWOsip1QAmKfzV+5wOH2YnKpZ eadcpkNSgwVh9U8W7y0xjVA+2GwfDRAnr3tpJddheZgQy0OiLOqh+gtUlQ+i38XyVlBd oWiJ05QQ3VAbyQcy1HA9Gtv8Cu4c7s+TAFcgirgp/VzrOLio6FSdy6kftO43CoHu3Tk+ diiTHUzT7IZYcSv2mjXF9tKeyNNMF7Ywdmn+bDY7jIY5WQ5o2IYCCvlz9qDzt+1ANfef ZfLUyXSRUbycpG8SnMU28s9nye19sfHR4khdF7jYitJTtprIib6UPVh6mTXXE7rFguzk g8ag== 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 n8-v6si267251pls.231.2018.02.21.13.58.24; Wed, 21 Feb 2018 13:58:39 -0800 (PST) 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 S1751379AbeBUV4J (ORCPT + 99 others); Wed, 21 Feb 2018 16:56:09 -0500 Received: from ipmail06.adl2.internode.on.net ([150.101.137.129]:51436 "EHLO ipmail06.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750790AbeBUV4I (ORCPT ); Wed, 21 Feb 2018 16:56:08 -0500 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail06.adl2.internode.on.net with ESMTP; 22 Feb 2018 08:26:06 +1030 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1eocMv-00079f-EI; Thu, 22 Feb 2018 08:56:05 +1100 Date: Thu, 22 Feb 2018 08:56:05 +1100 From: Dave Chinner To: Garry McNulty Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, hch@lst.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs/iomap: fix memory leak on error condition Message-ID: <20180221215605.GK6778@dastard> References: <20180221204128.5846-1-garrmcnu@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180221204128.5846-1-garrmcnu@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 21, 2018 at 08:41:28PM +0000, Garry McNulty wrote: > If the call to is_sync_kiocb() fails an error is returned without > freeing dio. Set the return code and jump to out_free_dio. > > Detected by CoverityScan, CID 1429424 ("Resource leak") Coverity is wrong. > Signed-off-by: Garry McNulty > --- > fs/iomap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/iomap.c b/fs/iomap.c > index afd163586aa0..65c5db38c15a 100644 > --- a/fs/iomap.c > +++ b/fs/iomap.c > @@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, > iomap_dio_set_error(dio, ret); > > if (!atomic_dec_and_test(&dio->ref)) { > - if (!is_sync_kiocb(iocb)) > - return -EIOCBQUEUED; > + if (!is_sync_kiocb(iocb)) { > + ret = -EIOCBQUEUED; > + goto out_free_dio; > + } This is where we return after AIO submission. The struct dio has already been attached to the bio we have submitted, and will be freed on IO completion. We are simply not waiting for IO completion here, instead leaving it to the completion code to free the struct dio and pass the completion status to the AIO code appropriately. Cheers, Dave. -- Dave Chinner david@fromorbit.com