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@xxxxxxxxxx> --- src/util/virjson.c | 82 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 14 deletions(-)
Attachment:
signature.asc
Description: PGP signature