提交 8d3f2d85 编写于 作者: S Sukrit Bhatnagar 提交者: Erik Skultety

util: usb: use VIR_AUTOFREE instead of VIR_FREE for scalar types

By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.
Signed-off-by: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 094c9e81
...@@ -90,29 +90,25 @@ VIR_ONCE_GLOBAL_INIT(virUSB) ...@@ -90,29 +90,25 @@ VIR_ONCE_GLOBAL_INIT(virUSB)
static int virUSBSysReadFile(const char *f_name, const char *d_name, static int virUSBSysReadFile(const char *f_name, const char *d_name,
int base, unsigned int *value) int base, unsigned int *value)
{ {
int ret = -1, tmp; int tmp;
char *buf = NULL; VIR_AUTOFREE(char *) buf = NULL;
char *filename = NULL; VIR_AUTOFREE(char *) filename = NULL;
char *ignore = NULL; char *ignore = NULL;
tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name); tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name);
if (tmp < 0) if (tmp < 0)
goto cleanup; return -1;
if (virFileReadAll(filename, 1024, &buf) < 0) if (virFileReadAll(filename, 1024, &buf) < 0)
goto cleanup; return -1;
if (virStrToLong_ui(buf, &ignore, base, value) < 0) { if (virStrToLong_ui(buf, &ignore, base, value) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse usb file %s"), filename); _("Could not parse usb file %s"), filename);
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
VIR_FREE(filename);
VIR_FREE(buf);
return ret;
} }
static virUSBDeviceListPtr static virUSBDeviceListPtr
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册