Received: by 10.223.185.116 with SMTP id b49csp1133259wrg; Wed, 21 Feb 2018 12:42:39 -0800 (PST) X-Google-Smtp-Source: AH8x225m5CQSxN+Y2gtUSjV43NEttjHpBoBGyRJmkcPH/9FAzOiTIGERIecLkM9AkVhVVc/QokFS X-Received: by 10.99.94.67 with SMTP id s64mr3702291pgb.312.1519245759608; Wed, 21 Feb 2018 12:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519245759; cv=none; d=google.com; s=arc-20160816; b=y+mneSwF+Lqhi3RDGpNs2rkFxhId20WDYcCDe85fq5nnNf7+E1MNd7hlDtFUGBcosC CvZ2TtZvOF/Rr3O3PHORVASMsb3v30HnSJ1YfWMGjtYCANLPX05t3pRsfy8I7kt0/l7I uJkWek2YlPaknM28mrmrobUxu29S3zZis0b1ERVi3GqKVwR5vNM9VSgfe8m8aXqN5Rfp 3h2uXDgARwBktP3KfEmmsoB6J+Qx5yPGQ4P/f0by4DFlBN/A9zhfznIVArOOHhzcuNNP Qe/RURJtioLMg01ovvDtSlPyXMFp6Oz0G47AXOVJgwIIOIRa1Z/nLrP2TeuZFnOinyJW VBzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=p0mJtrpZ5YTaCKDyy0/9JqW7A7sgpEwO/cjsQiysYdM=; b=PLhN/rt1LQLxMAiH92EEREIH8Zm+xeg45yNknl/I+/i0JqnySK1ei3ClQZrf3Ru0Uv 2Drnh6x351jK85XcK10g2O+d0Wn5NzaOTH29HSmPgH6z8pnaVWwEAJ5N+p0u5NVoUNEZ W4ObzQlybQ03t0SpjIxaLtM4VFBeVQ0FgizkMVCVrPrrVc9zrm8N4nsShbe9zMryjA/Y b09vNt7RnbS3yImfnWZ570yERXyqPu9Z82bBbO8GnkiKoaz3NGQvZ6IPBcj7RmLuJIGr yhISZZl4nXyB1KeRbxrDg1RVidfG18i6sxuLf5t54HCCGMrZHX0VP6WEOTmCbFTxNhKt 6EnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RiS3hqN/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj2-v6si284843plb.286.2018.02.21.12.42.24; Wed, 21 Feb 2018 12:42: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RiS3hqN/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751364AbeBUUlo (ORCPT + 99 others); Wed, 21 Feb 2018 15:41:44 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36668 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750831AbeBUUlm (ORCPT ); Wed, 21 Feb 2018 15:41:42 -0500 Received: by mail-wr0-f194.google.com with SMTP id u15so8194804wrg.3; Wed, 21 Feb 2018 12:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=p0mJtrpZ5YTaCKDyy0/9JqW7A7sgpEwO/cjsQiysYdM=; b=RiS3hqN/wht2HerQ0/GNbW1uW4Hljj1N+fWGwoyhmSK3L5/q4uuzB0LoRNfYCJlTyL Mivc1RnqQYV09FnnggHao5hY7VX9w3raSTo9b8wuy6ZaNfsVnDimdyo0iVqHahYEI7il O5iY7jj4/2DHllJSXt9G+zb6IEpCDPC1qhY2i+dYSXA3ucUX92EqHHHQMPf5kr7U+xLx WHTaXsCHpNZngnggr+TzN6Q5Gp+WIbGVw0PUtTgSE/EwHYfFVsolVsb8WbhdJ+XKpI2/ 4Y7JgWNdegHsacSLRuH8rEIJyvvu1nb1D7RrVt/xduGTb6lKzZA2NtATNnxeu+nV1y7f JQyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=p0mJtrpZ5YTaCKDyy0/9JqW7A7sgpEwO/cjsQiysYdM=; b=RljZ/5bo2JzvN+55kiNhzX5QDMBjqqSrPY1+FEZY+4gCo/KY5XTF05JQp+wnn+yctK JXW1NP4HWkw02+OSFTMrbEUXeGEPiOkjtJufRAa5jdkUeoN5ASi+sidC7cLYfuxgAC6q TIlI12SWxjG1q2N0sOfHcxNpkoOxVDk0NeqDclEnDLFAy5b5u1YepFF3Yu4nWUrUj1mG ifk9G/KaLJ5HZkyJ6X3+GFd4efOiD3gPYGmDOIIMEMqBcvUfHBksmXWgEJ15Mk4PYcCy Hf9wmBcWuqUmi96/psfRWJWp5gOTGAGaHVlr0J+tV1Dl8KFXqZAI6BVlH/tyAE3biQ2z ixFw== X-Gm-Message-State: APf1xPCRMKProLPJVqNh5TdkbkdOfFlME1qijSFN1YK3AbtyV/DE+vLw x4hLrO7aIoGX/kx/cjuvMRKcxuw= X-Received: by 10.28.211.195 with SMTP id k186mr2902203wmg.106.1519245701279; Wed, 21 Feb 2018 12:41:41 -0800 (PST) Received: from localhost.Home ([2a02:c7d:9b89:b200:b5dd:2c24:107:c8f3]) by smtp.gmail.com with ESMTPSA id y23sm20451163wra.9.2018.02.21.12.41.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 12:41:40 -0800 (PST) From: Garry McNulty To: linux-fsdevel@vger.kernel.org Cc: viro@zeniv.linux.org.uk, hch@lst.de, linux-kernel@vger.kernel.org, Garry McNulty Subject: [PATCH] fs/iomap: fix memory leak on error condition Date: Wed, 21 Feb 2018 20:41:28 +0000 Message-Id: <20180221204128.5846-1-garrmcnu@gmail.com> X-Mailer: git-send-email 2.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") 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; + } for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); -- 2.14.3