Re: [PATCH] libfdisk: Fix multipath partition seperators for user-friendly names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 21, 2018 at 11:07:34AM -0500, kmahlkuc@xxxxxxxxxxxxxxxxxx wrote:
> diff --git a/libfdisk/src/utils.c b/libfdisk/src/utils.c
> index 5ba9e04..031c783 100644
> --- a/libfdisk/src/utils.c
> +++ b/libfdisk/src/utils.c
> @@ -153,7 +153,18 @@ char *fdisk_partname(const char *dev, size_t partno)
>  	if ((strncmp(dev, _PATH_DEV_BYID, sizeof(_PATH_DEV_BYID) - 1) == 0) ||
>  	     strncmp(dev, _PATH_DEV_BYPATH, sizeof(_PATH_DEV_BYPATH) - 1) == 0 ||
>  	     strncmp(dev, "/dev/mapper", sizeof("/dev/mapper") - 1) == 0) {
> -	       p = "-part";
> +		asprintf(&res, "%.*s%zu", w, dev, partno);
> +		if (access(res, F_OK) == 0){
> +			p = "";
> +		} else {
> +			/* check for partition seperator "p" */
> +			p = "p";
> +			asprintf(&res, "%.*s%s%zu", w, dev, p, partno);

asprintf() always allocates a new string, right? ... in this case I
see a memory leak :-)

    Karel

> +			if (access(res, F_OK) != 0){
> +				/* otherwise, default to "-path" */
> +				p = "-part";
> +			}
> +		}
>  	}
>  
>  	if (asprintf(&res, "%.*s%s%zu", w, dev, p, partno) <= 0)
> -- 
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux