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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
> +}
> +

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]