[PATCH 003/103] virJSONValueObjectAddVArgs: Add new convertors for allocated strings

Ján Tomko jtomko at redhat.com
Fri Oct 8 11:48:59 UTC 2021


On a Thursday in 2021, Peter Krempa wrote:
>The 'f' and 'F' convertors add a string value to the JSON value object
>and free the passed pointer. This is helpful in case we need to e.g. add
>single use formatted values:
>

I'm not a fan of conditionally freeing the passed pointer based on some
value. Especially now that we have g_auto, it should be easy enough to
take care of in the caller.

> virJSONValueObjectAdd(props,
>                       "f:test1", g_strdup_printf("%s-test1", blah),
>                       "F:test2", virGetStringAndReportErrorOnNull(),
>                       NULL);
>
>With 'F' if the passed string is NULL no additional error is reported so
>the error is passed through.
>
>To prevent leaking the strings on reasonable failures we add an 'err'
>variable which skips the implementation of the conversions, but keeps
>iterating through the arguments.
>

>On hard programming errors (bad key format) the string is leaked but
>that should not be a problem in practice.

This sentence does not help sell it either :)

Jano

>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/util/virjson.c | 82 ++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 68 insertions(+), 14 deletions(-)
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20211008/da43e604/attachment-0001.sig>


More information about the libvir-list mailing list