[sheepdog] [PATCH] dog: don't free value if it is passed via command line
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Aug 15 03:33:37 CEST 2014
At Fri, 15 Aug 2014 10:32:05 +0900,
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.
>
> 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(-)
Ruoyu, if this patch looks OK to you, could you give me your
Reviewed-by: tag?
Thanks,
Hitoshi
>
> 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;
> --
> 1.8.3.2
>
More information about the sheepdog
mailing list