[libvirt] [PATCH v3 1/4] util: Introduce virJSONValueObjectStealArray
Peter Krempa
pkrempa at redhat.com
Wed Oct 5 13:55:51 UTC 2016
On Wed, Oct 05, 2016 at 09:47:15 -0400, John Ferlan wrote:
>
>
> On 10/05/2016 03:48 AM, Peter Krempa wrote:
> > 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.
> >
>
> D'oh - squash this in?
>
> diff --git a/src/util/virjson.c b/src/util/virjson.c
> index e705f53..1d8e6d5 100644
> --- a/src/util/virjson.c
> +++ b/src/util/virjson.c
> @@ -783,6 +783,9 @@ virJSONValueObjectSteal(virJSONValuePtr object,
> 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);
> + VIR_FREE(object->data.object.pairs[i].key);
> + VIR_DELETE_ELEMENT(object->data.object.pairs, i,
> + object->data.object.npairs);
> break;
> }
> }
yep, ACK
-------------- 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/eeddee7d/attachment-0001.sig>
More information about the libvir-list
mailing list