[libvirt] [PATCH 1/2] free cmd in virNetDevVethDelete

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> --- src/util/virnetdevveth.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 403961b..1085217 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -196,6 +196,7 @@ int virNetDevVethDelete(const char *veth) { virCommandPtr cmd = virCommandNewArgList("ip", "link", "del", veth, NULL); int status; + int ret = -1; if (virCommandRun(cmd, &status) < 0) return -1; @@ -203,11 +204,16 @@ int virNetDevVethDelete(const char *veth) if (status != 0) { if (!virNetDevExists(veth)) { VIR_DEBUG("Device %s already deleted (by kernel namespace cleanup)", veth); - return 0; + ret = 0; + goto cleanup; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to delete veth device %s"), veth); - return -1; + goto cleanup; } - return 0; + + ret = 0; +cleanup: + virCommandFree(cmd); + return ret; } -- 1.8.3.1

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> --- src/util/virnetdevveth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 1085217..2d727f1 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -110,6 +110,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) char *veth1auto = NULL; char *veth2auto = NULL; int vethNum = 0; + virCommandPtr cmd = NULL; size_t i; /* @@ -139,7 +140,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) vethNum = veth2num + 1; } - virCommandPtr cmd = virCommandNew("ip"); + cmd = virCommandNew("ip"); virCommandAddArgList(cmd, "link", "add", *veth1 ? *veth1 : veth1auto, "type", "veth", "peer", "name", @@ -169,6 +170,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) status); VIR_FREE(veth1auto); VIR_FREE(veth2auto); + virCommandFree(cmd); } virReportError(VIR_ERR_INTERNAL_ERROR, @@ -176,6 +178,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) MAX_VETH_RETRIES); cleanup: + virCommandFree(cmd); VIR_FREE(veth1auto); VIR_FREE(veth2auto); return ret; -- 1.8.3.1

On Fri, Oct 04, 2013 at 06:53:53PM +0800, Gao feng wrote:
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> --- src/util/virnetdevveth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 1085217..2d727f1 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -110,6 +110,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) char *veth1auto = NULL; char *veth2auto = NULL; int vethNum = 0; + virCommandPtr cmd = NULL; size_t i;
/* @@ -139,7 +140,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) vethNum = veth2num + 1; }
- virCommandPtr cmd = virCommandNew("ip"); + cmd = virCommandNew("ip"); virCommandAddArgList(cmd, "link", "add", *veth1 ? *veth1 : veth1auto, "type", "veth", "peer", "name", @@ -169,6 +170,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) status); VIR_FREE(veth1auto); VIR_FREE(veth2auto); + virCommandFree(cmd); }
This needs to set cmd = NULL, to avoid double-free if the loop terminates.
virReportError(VIR_ERR_INTERNAL_ERROR, @@ -176,6 +178,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) MAX_VETH_RETRIES);
cleanup: + virCommandFree(cmd); VIR_FREE(veth1auto); VIR_FREE(veth2auto); return ret;
ACK, I'll push with the mentioned fix. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Fri, Oct 04, 2013 at 06:53:52PM +0800, Gao feng wrote:
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> --- src/util/virnetdevveth.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 403961b..1085217 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -196,6 +196,7 @@ int virNetDevVethDelete(const char *veth) { virCommandPtr cmd = virCommandNewArgList("ip", "link", "del", veth, NULL); int status; + int ret = -1;
if (virCommandRun(cmd, &status) < 0) return -1;
This needs to jump to cleanup too.
@@ -203,11 +204,16 @@ int virNetDevVethDelete(const char *veth) if (status != 0) { if (!virNetDevExists(veth)) { VIR_DEBUG("Device %s already deleted (by kernel namespace cleanup)", veth); - return 0; + ret = 0; + goto cleanup; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to delete veth device %s"), veth); - return -1; + goto cleanup; } - return 0; + + ret = 0; +cleanup: + virCommandFree(cmd); + return ret; }
ACK, I'll push with the fix mentioned above Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 10/04/2013 07:03 PM, Daniel P. Berrange wrote:
On Fri, Oct 04, 2013 at 06:53:52PM +0800, Gao feng wrote:
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com> --- src/util/virnetdevveth.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 403961b..1085217 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -196,6 +196,7 @@ int virNetDevVethDelete(const char *veth) { virCommandPtr cmd = virCommandNewArgList("ip", "link", "del", veth, NULL); int status; + int ret = -1;
if (virCommandRun(cmd, &status) < 0) return -1;
This needs to jump to cleanup too.
oops, thanks!
@@ -203,11 +204,16 @@ int virNetDevVethDelete(const char *veth) if (status != 0) { if (!virNetDevExists(veth)) { VIR_DEBUG("Device %s already deleted (by kernel namespace cleanup)", veth); - return 0; + ret = 0; + goto cleanup; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to delete veth device %s"), veth); - return -1; + goto cleanup; } - return 0; + + ret = 0; +cleanup: + virCommandFree(cmd); + return ret; }
ACK, I'll push with the fix mentioned above
Daniel
participants (2)
-
Daniel P. Berrange
-
Gao feng