From: yangdongsheng Date: Tue, 28 May 2013 07:13:17 +0000 (+0800) Subject: util: fix the VIR_STRDUP when src is NULL X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2da3bc646e6fd1d07f4a663e8efaef8c7e0ba310;p=libvirt.git util: fix the VIR_STRDUP when src is NULL 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 Signed-off-by: Eric Blake --- diff --git a/src/util/virstring.c b/src/util/virstring.c index b244e6c75f..1937f82858 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -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)