[libvirt] [PATCH v3 1/4] util: Introduce virJSONValueObjectStealArray
Peter Krempa
pkrempa at redhat.com
Wed Oct 5 07:48:31 UTC 2016
On Tue, Oct 04, 2016 at 11:28:55 -0400, John Ferlan wrote:
> Provide the Steal API for any code paths that will desire to grab the
> entire array and then free it afterwards rather than relying to freeing
> the whole chain from the reply.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
> src/libvirt_private.syms | 1 +
> src/util/virjson.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> src/util/virjson.h | 2 ++
> 3 files changed, 46 insertions(+)
[...]
> diff --git a/src/util/virjson.c b/src/util/virjson.c
> index b6d9a34..e705f53 100644
> --- a/src/util/virjson.c
> +++ b/src/util/virjson.c
> @@ -770,6 +770,27 @@ virJSONValueObjectGet(virJSONValuePtr object,
> }
>
>
> +static virJSONValuePtr
> +virJSONValueObjectSteal(virJSONValuePtr object,
> + const char *key)
> +{
> + size_t i;
> + virJSONValuePtr obj = NULL;
> +
> + if (object->type != VIR_JSON_TYPE_OBJECT)
> + return NULL;
> +
> + for (i = 0; i < object->data.object.npairs; i++) {
> + if (STREQ(object->data.object.pairs[i].key, key)) {
> + VIR_STEAL_PTR(obj, object->data.object.pairs[i].value);
You steal the data but don't delete the key from the object which makes
the object invalid.
> + break;
> + }
> + }
> +
> + return obj;
> +}
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20161005/0072a08e/attachment-0001.sig>
More information about the libvir-list
mailing list