[libvirt] [PATCH 1/4] Make avahi startup more robust.

Eric Blake eblake at redhat.com
Wed Apr 21 16:25:40 UTC 2010


On 04/21/2010 10:03 AM, Chris Lalancette wrote:
> If the hostname of the current virtualization machine
> could not be resolved, then libvirtd would fail to
> start.  However, for disconnected operation (on a laptop,
> for instance) the hostname may very legitimately not
> be resolvable.  This patch makes it so that if we can't
> resolve the hostname, avahi doesn't fail, it just uses
> a less useful MDNS string.

ACK on the concept, but fix the corner-case memory leak before pushing.

> 
>          if (!mdns_name) {
> -            char groupname[64], *localhost, *tmp;
> +            char *groupname, *localhost, *tmp;
>              /* Extract the host part of the potentially FQDN */
>              localhost = virGetHostname(NULL);

Here, localhost can be allocated...

>              if (localhost == NULL)
> +                ret = virAsprintf(&groupname, "Virtualization Host");
> +            else {
> +                if ((tmp = strchr(localhost, '.')))
> +                    *tmp = '\0';
> +                ret = virAsprintf(&groupname, "Virtualization Host %s",
> +                                  localhost);

then groupname fails...

> +            }
> +            if (ret < 0) {
> +                virReportOOMError();
>                  goto cleanup;

...and we leak localhost.

> -
> -            if ((tmp = strchr(localhost, '.')))
> -                *tmp = '\0';
> -            snprintf(groupname, sizeof(groupname)-1, "Virtualization Host %s", localhost);
> -            groupname[sizeof(groupname)-1] = '\0';
> +            }
>              group = libvirtd_mdns_add_group(server->mdns, groupname);
>              VIR_FREE(localhost);
> +            VIR_FREE(groupname);

But on success, there is no leak.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100421/c7d376e7/attachment-0001.sig>


More information about the libvir-list mailing list