On 05/03/2013 08:53 AM, Michal Privoznik wrote:
---
daemon/libvirtd-config.c | 50 +++++----------
daemon/libvirtd.c | 29 +++++----
daemon/remote.c | 161 ++++++++++++++++++-----------------------------
3 files changed, 92 insertions(+), 148 deletions(-)
Good sign that our interface is nice, because using it shrinks the code
base.
@@ -287,10 +287,10 @@ daemonUnixSocketPaths(struct daemonConfig
*config,
goto no_memory;
} else {
if (privileged) {
- if (!(*sockfile = strdup(LOCALSTATEDIR
"/run/libvirt/libvirt-sock")))
- goto no_memory;
- if (!(*rosockfile = strdup(LOCALSTATEDIR
"/run/libvirt/libvirt-sock-ro")))
- goto no_memory;
+ if (VIR_STRDUP(*sockfile, LOCALSTATEDIR
"/run/libvirt/libvirt-sock") < 0)
+ goto error;
+ if (VIR_STRDUP(*rosockfile, LOCALSTATEDIR
"/run/libvirt/libvirt-sock-ro") < 0)
+ goto error;
Could merge these two 'if' into one, especially since you were doing it
elsewhere in this patch, but not essential.
@@ -1172,7 +1173,7 @@ int main(int argc, char **argv) {
case 'p':
VIR_FREE(pid_file);
- if (!(pid_file = strdup(optarg))) {
+ if (VIR_STRDUP_QUIET(pid_file, optarg) < 0) {
VIR_ERROR(_("Can't allocate memory"));
exit(EXIT_FAILURE);
One of the few cases where _QUIET is right, since main() is early enough
that normal error reporting may not be initialized yet :)
@@ -473,18 +447,18 @@ static int
remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED,
memset(&data, 0, sizeof(data));
if (oldSrcPath &&
((VIR_ALLOC(oldSrcPath_p) < 0) ||
- !(*oldSrcPath_p = strdup(oldSrcPath))))
+ VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0))
goto mem_error;
Yep, I said I could live with the double OOM for now, and that we'll
clean it up when we make our next pass over VIR_ALLOC.
@@ -4779,14 +4739,14 @@ static void
make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src)
{
dom_dst->id = dom_src->id;
- dom_dst->name = strdup(dom_src->name);
+ ignore_value(VIR_STRDUP_QUIET(dom_dst->name, dom_src->name));
memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN);
Aargh, I promised to work on this, and still haven't gotten around to
it. But it's an independent cleanup to make the make_nonnull_ functions
not return half-baked objects, so doesn't hold up your patch.
ACK.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org