[sheepdog] [PATCH] dog: don't free value if it is passed via command line

Ruoyu liangry at ucweb.com
Fri Aug 15 04:26:42 CEST 2014


On 2014年08月15日 09:32, Hitoshi Mitake wrote:
> vdi_setattr() has two way of obtaining value of attr:
> 1. command line parameter
> 2. read from stdin
>
> In a case of 1, the value shouldn't be freed because it is not in heap
> area. But current dog does it. This patch removes this invalid free.
In case 1, what about value = strdup(argv[optind++]) to alloc the space 
in stack area?
Then, free will fit for both situations.
Because I think the new variable value_allocated is confused for developers.
>
> Reported-by: Ruoyu <liangry at ucweb.com>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
>   dog/vdi.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 84715b3..1d8cc6e 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -1278,6 +1278,7 @@ static int vdi_setattr(int argc, char **argv)
>   	const char *vdiname = argv[optind++], *key;
>   	char *value = NULL;
>   	uint64_t offset;
> +	bool value_alloced = false;
>   
>   	key = argv[optind++];
>   	if (!key) {
> @@ -1289,6 +1290,7 @@ static int vdi_setattr(int argc, char **argv)
>   	value = argv[optind++];
>   	if (!value && !vdi_cmd_data.delete) {
>   		value = xmalloc(SD_MAX_VDI_ATTR_VALUE_LEN);
> +		value_alloced = true;
>   
>   		offset = 0;
>   reread:
> @@ -1333,7 +1335,7 @@ reread:
>   	}
>   
>   out:
> -	if (value)
> +	if (value_alloced)
>   		free(value);
>   
>   	return ret;





More information about the sheepdog mailing list