[dm-devel] [PATCH 6/6] multipathd: return NULL if MALLOC fails in alloc_waiteri, func
Martin Wilck
mwilck at suse.com
Mon Aug 17 09:21:18 UTC 2020
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 <liuzhiqiang26 at huawei.com>
> Signed-off-by: lixiaokeng <lixiaokeng at huawei.com>
> ---
> 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
More information about the dm-devel
mailing list