From: Zhiqiang Liu Subject: Re: [PATCH 6/6] multipathd: return NULL if MALLOC fails in alloc_waiteri, func Date: Mon, 17 Aug 2020 22:42:49 +0800 Message-ID: References: <351fa23b-b730-ce22-7e89-24f26a693a6a@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: 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: Martin Wilck , bmarzins@redhat.com, Christophe Varoqui , Zdenek Kabelac Cc: linfeilong , Yanxiaodan , dm-devel@redhat.com, lixiaokeng List-Id: dm-devel.ids On 2020/8/17 17:21, Martin Wilck wrote: > On Sun, 2020-08-16 at 09:46 +0800, Zhiqiang Liu wrote: >> In alloc_waiter func, if MALLOC fails, wp is equal to NULL. >> If now we call memset(wp), segmentation fault will occur. >> >> Signed-off-by: Zhiqiang Liu >> Signed-off-by: lixiaokeng >> --- >> multipathd/waiter.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/multipathd/waiter.c b/multipathd/waiter.c >> index e645766..80e6e6e 100644 >> --- a/multipathd/waiter.c >> +++ b/multipathd/waiter.c >> @@ -33,8 +33,10 @@ static struct event_thread *alloc_waiter (void) >> struct event_thread *wp; >> >> wp = (struct event_thread *)MALLOC(sizeof(struct >> event_thread)); >> - memset(wp, 0, sizeof(struct event_thread)); >> + if (!wp) >> + return NULL; >> >> + memset(wp, 0, sizeof(struct event_thread)); >> return wp; >> } >> > > This is correct, but while you're at it, please also remove the > superfluous memset() call (counterintuitively, MALLOC(x) maps to > calloc(1, x)). > > Martin > Thanks for your suggestion. I will remove the memset() call in v2 patch. Zhiqiang > > > . >