[dm-devel] [PATCH 02/14] libmultipath: check malloc return value in, print_foreign_topology
Martin Wilck
mwilck at suse.com
Thu Sep 3 17:29:10 UTC 2020
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 <lixiaokeng at huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26 at huawei.com>
> Signed-off-by: Linfeilong <linfeilong at huawei.com>
> ---
> 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;
> --
>
More information about the dm-devel
mailing list