From patchwork Thu Aug 1 02:02:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 1140191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45zYTw5YtBz9sMr for ; Thu, 1 Aug 2019 12:03:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726334AbfHACC6 (ORCPT ); Wed, 31 Jul 2019 22:02:58 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3286 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726185AbfHACC6 (ORCPT ); Wed, 31 Jul 2019 22:02:58 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id AF281736122E02F675B2; Thu, 1 Aug 2019 10:02:55 +0800 (CST) Received: from [127.0.0.1] (10.184.225.177) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Thu, 1 Aug 2019 10:02:43 +0800 To: , =?utf-8?q?Aur=C3=A9lien_Aptel?= , , , , , , , , From: Zhiqiang Liu Subject: [PATCH cifs-utils] mount.cifs.c: fix memory leaks in main func CC: , Mingfangsen , zhangsaisai Message-ID: Date: Thu, 1 Aug 2019 10:02:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 X-Originating-IP: [10.184.225.177] X-CFilter-Loop: Reflected Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Jiawen Liu In mount.cifs module, orgoptions and mountpoint in the main func point to the memory allocated by func realpath and strndup respectively. However, they are not freed before the main func returns so that the memory leaks occurred. The memory leak problem is reported by LeakSanitizer tool. LeakSanitizer url: "https://github.com/google/sanitizers" Here I free the pointers orgoptions and mountpoint before main func returns. Fixes:7549ad5e7126 ("memory leaks: caused by func realpath and strndup") Signed-off-by: Jiawen Liu Reported-by: Jin Du Reviewed-by: Saisai Zhang --- mount.cifs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mount.cifs.c b/mount.cifs.c index ae7a899..029f01a 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -1830,6 +1830,7 @@ assemble_mountinfo(struct parsed_mount_info *parsed_info, } assemble_exit: + free(orgoptions); return rc; } @@ -1994,8 +1995,11 @@ int main(int argc, char **argv) /* chdir into mountpoint as soon as possible */ rc = acquire_mountpoint(&mountpoint); - if (rc) + if (rc) { + free(mountpoint); + free(orgoptions); return rc; + } /* * mount.cifs does privilege separation. Most of the code to handle @@ -2014,6 +2018,7 @@ int main(int argc, char **argv) /* child */ rc = assemble_mountinfo(parsed_info, thisprogram, mountpoint, orig_dev, orgoptions); + free(mountpoint); return rc; } else { /* parent */ @@ -2149,5 +2154,6 @@ mount_exit: } free(options); free(orgoptions); + free(mountpoint); return rc; }