From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Wilck Subject: Re: [PATCH 02/14] libmultipath: check malloc return value in, print_foreign_topology Date: Thu, 03 Sep 2020 19:29:10 +0200 Message-ID: References: <37544d4c-950f-4281-3b66-e4d1884c5167@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: lixiaokeng , Benjamin Marzinski , Christophe Varoqui , dm-devel mailing list Cc: linfeilong , "liuzhiqiang (I)" List-Id: dm-devel.ids On Wed, 2020-09-02 at 15:16 +0800, lixiaokeng wrote: > We check the return value of malloc in print_foreign_topology. > > Signed-off-by: Lixiaokeng > Signed-off-by: Zhiqiang Liu > Signed-off-by: Linfeilong > --- > libmultipath/foreign.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c > index e8f61351..44f32d03 100644 > --- a/libmultipath/foreign.c > +++ b/libmultipath/foreign.c > @@ -545,6 +545,10 @@ void print_foreign_topology(int verbosity) > char *buf = NULL, *tmp = NULL; > > buf = malloc(buflen); > + if (!buf) { > + condlog (0, "malloc buf failed."); > + return; > + } Just replace the malloc() by calloc() please, and remove the buf[0] initialization. No need for an error message. Martin > buf[0] = '\0'; > while (buf != NULL) { > char *c = buf; > -- >