From: Martin Wilck Subject: [PATCH 20/72] libmultipath: _init_foreign(): fix possible memory leak Date: Sat, 12 Oct 2019 21:28:02 +0000 Message-ID: <20191012212703.12989-21-martin.wilck@suse.com> References: <20191012212703.12989-1-martin.wilck@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20191012212703.12989-1-martin.wilck@suse.com> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Christophe Varoqui , Benjamin Marzinski Cc: "dm-devel@redhat.com" , Martin Wilck List-Id: dm-devel.ids From: Martin Wilck free_pre() wasn't called if scandir() failed. Fix it. Signed-off-by: Martin Wilck --- libmultipath/foreign.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c index 4b34e141..9ef8ad19 100644 --- a/libmultipath/foreign.c +++ b/libmultipath/foreign.c @@ -148,7 +148,7 @@ static int _init_foreign(const char *multipath_dir, const char *enable) (void)regerror(r, enable_re, errbuf, sizeof(errbuf)); condlog (2, "%s: error compiling enable_foreign = \"%s\": \"%s\"", __func__, str, errbuf); - free_pre(&enable_re); + goto out_free_pre; } } @@ -157,13 +157,13 @@ static int _init_foreign(const char *multipath_dir, const char *enable) if (r == 0) { condlog(3, "%s: no foreign multipath libraries found", __func__); - return 0; + goto out_free_pre; } else if (r < 0) { - r = errno; - condlog(1, "%s: error %d scanning foreign multipath libraries", - __func__, r); + r = -errno; + condlog(1, "%s: error scanning foreign multipath libraries: %m", + __func__); _cleanup_foreign(); - return -r; + goto out_free_pre; } sr.di = di; @@ -249,9 +249,11 @@ static int _init_foreign(const char *multipath_dir, const char *enable) dl_err: free_foreign(fgn); } + r = 0; pthread_cleanup_pop(1); /* free_scandir_result */ +out_free_pre: pthread_cleanup_pop(1); /* free_pre */ - return 0; + return r; } int init_foreign(const char *multipath_dir, const char *enable) -- 2.23.0