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

Re: [libvirt] [PATCH v3 19/20] Refactor qemuCapsParseDeviceStr to work from data tables



On Tue, Sep 25, 2012 at 19:00:12 +0100, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange redhat com>
> 
> Currently the qemuCapsParseDeviceStr method has a bunch of open
> coded string searches/comparisons to detect devices and their
> properties. Soon this data will be obtained from QMP queries
> instead of -device help output. Maintaining the list of device
> and properties in two places is undesirable. Thus the existing
> qemuCapsParseDeviceStr() method needs to be refactored to
> separate the device types and properties from the actual
> search code.
> 
> Thus the -device help output is now parsed to construct a
> list of device names, and device properties. These are then
> checked against a set of datatables to set the capability
> flags
> 
> Signed-off-by: Daniel P. Berrange <berrange redhat com>
> ---
>  src/qemu/qemu_capabilities.c | 364 ++++++++++++++++++++++++++++++-------------
>  src/qemu/qemu_capabilities.h |   3 +-
>  tests/qemuhelptest.c         |   2 +-
>  3 files changed, 259 insertions(+), 110 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 9c4f3be..c4d36f9 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -1233,6 +1233,262 @@ cleanup:
...
> +qemuCapsParseDeviceStrObjectTypes(const char *str,
> +                                  char ***types)
> +{
> +    const char *tmp = str;
> +    int ret = -1;
> +    size_t ntypelist = 0;
> +    char **typelist = NULL;
> +
> +    *types = NULL;
> +
> +    while ((tmp = strstr(tmp, OBJECT_TYPE_PREFIX))) {
> +        char *end;
> +        tmp += strlen(OBJECT_TYPE_PREFIX);
> +        end = strstr(tmp, "\"");
> +        if (!end) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("Malformed QEMU device list string, missing quote"));
> +            goto cleanup;
> +        }
> +
> +        if (VIR_EXPAND_N(typelist, ntypelist, 1) < 0) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +        if (!(typelist[ntypelist-1] = strndup(tmp, end-tmp))) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +    }
> +
> +    *types = typelist;
> +    ret = ntypelist;
> +
> +cleanup:
> +    return ret;
> +}

typelist and all string referenced from it are leaked in case of error

> +
> +
> +static int
> +qemuCapsParseDeviceStrObjectProps(const char *str,
> +                                  const char *type,
> +                                  char ***props)
> +{
> +    const char *tmp = str;
> +    int ret = -1;
> +    size_t nproplist = 0;
> +    char **proplist = NULL;
> +
> +    VIR_DEBUG("Extract type %s", type);
> +    *props = NULL;
> +
> +    while ((tmp = strchr(tmp, '\n'))) {
> +        char *end;
> +        tmp += 1;
> +
> +        if (*tmp == '\0')
> +            break;
> +
> +        if (STRPREFIX(tmp, OBJECT_TYPE_PREFIX))
> +            continue;
> +
> +        if (!STRPREFIX(tmp, type))
> +            continue;
> +
> +        tmp += strlen(type);
> +        if (*tmp != '.')
> +            continue;
> +        tmp++;
> +
> +        end = strstr(tmp, "=");
> +        if (!end) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("Malformed QEMU device list string, missing '='"));
> +            goto cleanup;
> +        }
> +        if (VIR_EXPAND_N(proplist, nproplist, 1) < 0) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +        if (!(proplist[nproplist-1] = strndup(tmp, end-tmp))) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +    }
> +
> +    *props = proplist;
> +    ret = nproplist;
> +
> +cleanup:
> +    return ret;
> +}

Similar memory leak on error path.

Jirka


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