mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-06-09 03:01:53 -04:00
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:
parent
6d1c242433
commit
4f975d0071
41 changed files with 240 additions and 194 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue