Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp18087ybc; Mon, 18 Nov 2019 19:14:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz5uztAMwNLNYUSuAq3SbQHkJPh/Ps7mnpyunquBb/la7TW6UUGQ1KlhthqvPl3EvBBmkwt X-Received: by 2002:a17:906:7c4e:: with SMTP id g14mr31288590ejp.150.1574133279312; Mon, 18 Nov 2019 19:14:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574133279; cv=none; d=google.com; s=arc-20160816; b=X2RG9OMWI+4CuUIL9U0KKsySz526JZVsa2WbyrOaGGn1preDLOpcXVDpdZFNIOtWBk A+mt9dX07B9uD1UH1Mx5JhpHfmQXeqRQJkooxTaU7xqrRMVLrk+C6VtzcgY90dVuNa7v s+L126hbhRo2y3xMZJeoRQdSFP81Gakks+QeAYvliLlKQXnI+xxgOEKIuEGLOOzcUugb fh0/s3Y5//g9tK0CHH//FejGZtvDwWKirWPCRrg8C5gjPl1+MjVHu6/XX3AfIKzg4FJw xpKrYNpdYku1MzLbZPVkGm5Ed8YLTUDC/0AUsluX327yMVuLlBzzEAMTNB2a0h2Y2SVJ 56qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from; bh=0W3oxUKgRR9+GHYPXMk9RhgJkKWrXFlLkVwU9OamfA4=; b=0Oo7IV+831XCVn5PSGY3uJPYXwKOMJ1VGTGSswXGrmQ0I4/yXP0kAXTP3A4yVEUPTo 9eq6QEi/P5cy3esURNA/bk040TRkEA4j9WIayv+U1Ahz7dfajmX3CZR5ba+Kgs6sGf/6 Q/SmaUnhB68jAeorU5nJXcrtbpqwh9t70ifhamV1akNifdzBWXxsoqNG0CQcQR9prwvj c2G50lyUB/uh634rvYZFzRrhv6OeBJMctMGD+qY8SryLiIY4FMJhkRswtkK0CaIR+J+P RoOddteWMy+2qG7R2CWmUOAvdWo6M6w1TNUwY5VhvT7nHIfcVi4fmhDHQ7YZWjdo3TZO p23Q== 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 f50si11318731edb.422.2019.11.18.19.14.15; Mon, 18 Nov 2019 19:14: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 S1727538AbfKSDJi (ORCPT + 99 others); Mon, 18 Nov 2019 22:09:38 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:51444 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727428AbfKSDJi (ORCPT ); Mon, 18 Nov 2019 22:09:38 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9FF187A00CF49560C90A; Tue, 19 Nov 2019 11:09:36 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Tue, 19 Nov 2019 11:09:30 +0800 From: Sun Ke To: , , , , , Subject: [PATCH] nbd:fix memory leak in nbd_get_socket() Date: Tue, 19 Nov 2019 11:16:48 +0800 Message-ID: <1574133408-77202-1-git-send-email-sunke32@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before return NULL,put the sock first. Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup") Signed-off-by: Sun Ke --- drivers/block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index a94ee45..19e7599 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd, if (sock->ops->shutdown == sock_no_shutdown) { dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n"); *err = -EINVAL; + sockfd_put(sock); return NULL; } -- 2.7.4