提交 a3400466 编写于 作者: D dunrong huang 提交者: Anthony Liguori

qdev: Fix memory leak

The str allocated in visit_type_str was not freed.

The visit_type_str function is an input visitor(<QMP/String/etc>-to-native)
here, it will allocate memory for caller, so the caller is responsible for
freeing the memory.
Reviewed-by: NStefan Weil <sw@weilnetz.de>
Signed-off-by: Ndunrong huang <riegamaths@gmail.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 2a633c46
...@@ -753,10 +753,12 @@ static void set_mac(Object *obj, Visitor *v, void *opaque, ...@@ -753,10 +753,12 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
} }
mac->a[i] = strtol(str+pos, &p, 16); mac->a[i] = strtol(str+pos, &p, 16);
} }
g_free(str);
return; return;
inval: inval:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
g_free(str);
} }
PropertyInfo qdev_prop_macaddr = { PropertyInfo qdev_prop_macaddr = {
...@@ -825,7 +827,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, ...@@ -825,7 +827,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
uint32_t *ptr = qdev_get_prop_ptr(dev, prop); uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
unsigned int slot, fn, n; unsigned int slot, fn, n;
Error *local_err = NULL; Error *local_err = NULL;
char *str = (char *)""; char *str;
if (dev->state != DEV_STATE_CREATED) { if (dev->state != DEV_STATE_CREATED) {
error_set(errp, QERR_PERMISSION_DENIED); error_set(errp, QERR_PERMISSION_DENIED);
...@@ -848,10 +850,12 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, ...@@ -848,10 +850,12 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
goto invalid; goto invalid;
} }
*ptr = slot << 3 | fn; *ptr = slot << 3 | fn;
g_free(str);
return; return;
invalid: invalid:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
g_free(str);
} }
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len) static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册