[libvirt] [PATCHv6 5/8] storage: Add storage file backends for gluster

John Ferlan jferlan at redhat.com
Fri Feb 14 11:24:28 UTC 2014


Coverity has found a RESOURCE_LEAK...

<...snip...>

> +static int
> +virStorageFileBackendGlusterInit(virStorageFilePtr file)
> +{
> +    virStorageFileBackendGlusterPrivPtr priv = NULL;
> +    virDomainDiskHostDefPtr host = &(file->hosts[0]);
> +    const char *hostname = host->name;
> +    int port = 0;
> +
> +    VIR_DEBUG("initializing gluster storage file %p(%s/%s)",
> +              file, hostname, file->path);
> +
> +    if (VIR_ALLOC(priv) < 0)
> +        return -1;
> +

We have 'priv' here... but anywhere through to "error:" if we fail, then
priv isn't free'd.


> +    if (VIR_STRDUP(priv->volname, file->path) < 0)
> +        goto error;
> +
> +    if (!(priv->path  = strchr(priv->volname, '/'))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("invalid path of gluster volume: '%s'"),
> +                       file->path);
> +        goto error;
> +    }
> +
> +    *priv->path = '\0';
> +    priv->path++;
> +
> +    if (host->port &&
> +        virStrToLong_i(host->port, NULL, 10, &port) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to parse port number '%s'"),
> +                       host->port);
> +        goto error;
> +    }
> +
> +    if (host->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX)
> +        hostname = host->socket;
> +
> +
> +    if (!(priv->vol = glfs_new(priv->volname))) {
> +        virReportOOMError();
> +        goto error;
> +    }
> +
> +    if (glfs_set_volfile_server(priv->vol,
> +                                virDomainDiskProtocolTransportTypeToString(host->transport),
> +                                hostname, port) < 0) {
> +        virReportSystemError(errno,
> +                             _("failed to set gluster volfile server '%s'"),
> +                             hostname);
> +        goto error;
> +    }
> +
> +    if (glfs_init(priv->vol) < 0) {
> +        virReportSystemError(errno,
> +                             _("failed to initialize gluster connection to "
> +                               "server: '%s'"), hostname);
> +        goto error;
> +    }
> +
> +    file->priv = priv;
> +
> +    return 0;
> +
> +error:
> +    VIR_FREE(priv->volname);
> +    glfs_fini(priv->vol);

Adding the free here would be the salve for Coverity.

John
> +
> +    return -1;
> +}
> +




More information about the libvir-list mailing list