[libvirt] [PATCH v6 18/23] conf: support recording ports against virNetworkObjPtr

John Ferlan jferlan at redhat.com
Tue Jun 18 16:23:01 UTC 2019


[...]

> +
> +
> +int
> +virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
> +                            const char *stateDir)
> +{
> +    char *dir;
> +    DIR *dh;
> +    struct dirent *de;
> +    int rc;
> +    int ret = -1;
> +
> +    if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
> +        goto cleanup;
> +
> +    if ((rc = virDirOpenIfExists(&dh, dir)) <= 0) {

Coverity notes @dh is leaked (and would need init to NULL too)

> +        ret = rc;
> +        goto cleanup;
> +    }
> +
> +    while ((rc = virDirRead(dh, &de, dir)) > 0) {
> +        char *file = NULL;
> +
> +        if (!virStringStripSuffix(de->d_name, ".xml"))
> +            continue;
> +
> +        if (virAsprintf(&file, "%s/%s.xml", dir, de->d_name) < 0)
> +            goto cleanup;
> +
> +        if (unlink(file) < 0 && errno != ENOENT)
> +            VIR_WARN("Unable to delete %s", file);
> +
> +        VIR_FREE(file);
> +    }
> +
> +    virHashRemoveAll(net->ports);
> +
> +    ret = 0;
> + cleanup:
> +    return ret;
> +}
> +

[...]

> +
> +int
> +virNetworkObjPortListExport(virNetworkPtr net,
> +                            virNetworkObjPtr obj,
> +                            virNetworkPortPtr **ports,
> +                            virNetworkPortListFilter filter)
> +{
> +    virNetworkObjPortListExportData data = {
> +        net, obj->def, NULL, filter, 0, false,
> +    };
> +    int ret = -1;
> +
> +    *ports = NULL;
> +
> +    if (ports && VIR_ALLOC_N(data.ports, virHashSize(obj->ports) + 1) < 0)

Coverity notes that checking @ports here is a bit too late since *ports
deref above would have already caused a failure

John

> +        goto cleanup;
> +
> +    virHashForEach(obj->ports, virNetworkObjPortListExportCallback, &data);
> +

[...]




More information about the libvir-list mailing list