treewide: add error checking to spa_json_builder_close

There could have been a write error or allocation error while building
the json file that we can detect in spa_json_builder_close().

Error out instead of silently using a truncated JSON.

Use spa_autofree for the memory to make cleanup easier.
This commit is contained in:
Wim Taymans 2026-05-13 18:14:44 +02:00
parent 6d1c242433
commit 4f975d0071
41 changed files with 240 additions and 194 deletions

View file

@ -4,6 +4,7 @@
#include <unistd.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -299,7 +300,7 @@ static int load_state(struct maap *maap)
static int save_state(struct maap *maap)
{
struct spa_json_builder b;
char *ptr;
spa_autofree char *ptr = NULL;
size_t size;
char key[512];
uint32_t count;
@ -317,10 +318,10 @@ static int save_state(struct maap *maap)
spa_json_builder_object_uint(&b, "count", maap->count);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "]");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
count = pw_properties_set(maap->props, "maap.addresses", ptr);
free(ptr);
if (count > 0) {
snprintf(key, sizeof(key), "maap.%s", maap->server->ifname);