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

util: netdevtap: 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>
上级 2d9be4d8
...@@ -400,16 +400,15 @@ int virNetDevTapCreate(char **ifname, ...@@ -400,16 +400,15 @@ int virNetDevTapCreate(char **ifname,
if (strstr(*ifname, "%d") != NULL) { if (strstr(*ifname, "%d") != NULL) {
size_t i; size_t i;
for (i = 0; i <= IF_MAXUNIT; i++) { for (i = 0; i <= IF_MAXUNIT; i++) {
char *newname; VIR_AUTOFREE(char *) newname = NULL;
if (virAsprintf(&newname, *ifname, i) < 0) if (virAsprintf(&newname, *ifname, i) < 0)
goto cleanup; goto cleanup;
if (virNetDevExists(newname) == 0) { if (virNetDevExists(newname) == 0) {
newifname = newname; VIR_STEAL_PTR(newifname, newname);
break; break;
} }
VIR_FREE(newname);
} }
if (newifname) { if (newifname) {
VIR_FREE(*ifname); VIR_FREE(*ifname);
...@@ -423,7 +422,7 @@ int virNetDevTapCreate(char **ifname, ...@@ -423,7 +422,7 @@ int virNetDevTapCreate(char **ifname,
} }
if (tapfd) { if (tapfd) {
char *dev_path = NULL; VIR_AUTOFREE(char *) dev_path = NULL;
if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0)
goto cleanup; goto cleanup;
...@@ -431,11 +430,8 @@ int virNetDevTapCreate(char **ifname, ...@@ -431,11 +430,8 @@ int virNetDevTapCreate(char **ifname,
virReportSystemError(errno, virReportSystemError(errno,
_("Unable to open %s"), _("Unable to open %s"),
dev_path); dev_path);
VIR_FREE(dev_path);
goto cleanup; goto cleanup;
} }
VIR_FREE(dev_path);
} }
if (virNetDevSetName(ifr.ifr_name, *ifname) == -1) if (virNetDevSetName(ifr.ifr_name, *ifname) == -1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册