[dm-devel] [PATCH 06/14] kpartx: check return value of malloc in main func
Martin Wilck
mwilck at suse.com
Thu Sep 3 19:23:37 UTC 2020
On Wed, 2020-09-02 at 15:19 +0800, lixiaokeng wrote:
> In main func of kpartx.c, we should check return value of
> malloc before using it.
>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26 at huawei.com>
> Signed-off-by: Lixiaokeng <lixiaokeng at huawei.com>
> ---
> kpartx/kpartx.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
> index 98f6176e..2f6dea7c 100644
> --- a/kpartx/kpartx.c
> +++ b/kpartx/kpartx.c
> @@ -384,6 +384,10 @@ main(int argc, char **argv){
>
> if (delim == NULL) {
> delim = malloc(DELIM_SIZE);
> + if (!delim) {
> + fprintf(stderr, "malloc delim failed.\n");
> + exit(1);
> + }
> memset(delim, 0, DELIM_SIZE);
> set_delimiter(mapname, delim);
> }
Please have a look at kpartx' xmalloc() function.
Regards,
Martin
More information about the dm-devel
mailing list