From 2da3bc646e6fd1d07f4a663e8efaef8c7e0ba310 Mon Sep 17 00:00:00 2001 From: yangdongsheng Date: Tue, 28 May 2013 15:13:17 +0800 Subject: [PATCH] util: fix the VIR_STRDUP when src is NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/util/virstring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)