]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: fix the VIR_STRDUP when src is NULL
authoryangdongsheng <yangds.fnst@cn.fujitsu.com>
Tue, 28 May 2013 07:13:17 +0000 (15:13 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 28 May 2013 11:57:01 +0000 (05:57 -0600)
When src is NULL, VIR_STRDUP will return 0 directly.
This patch will set dest to NULL before VIR_STRDUP return.

Example:
[root@yds-pc libvirt]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type: 'help' for help with commands
'quit' to quit

virsh # connect
error: Failed to connect to the hypervisor
error: internal error Unable to parse URI �N�*

Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/virstring.c

index b244e6c75f72746431caa5ac9af79438ce9cb16c..1937f82858fc2353c92274917d136b2c567f4e40 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -540,6 +540,7 @@ virStrdup(char **dest,
           const char *funcname,
           size_t linenr)
 {
+    *dest = NULL;
     if (!src)
         return 0;
     if (!(*dest = strdup(src))) {
@@ -583,6 +584,7 @@ virStrndup(char **dest,
            const char *funcname,
            size_t linenr)
 {
+    *dest = NULL;
     if (!src)
         return 0;
     if (n < 0)