Skip to content

Commit

Permalink
iiod: Free XML string after use
Browse files Browse the repository at this point in the history
Now that iio_context_get_xml() returns a heap-allocated string, we need
to de-allocate it with free() after use.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jan 30, 2024
1 parent 4d511a9 commit 58127c8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions iiod/iiod.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,23 @@ static void sig_handler_usr1(int sig)

static void *get_xml_zstd_data(const struct iio_context *ctx, size_t *out_len)
{
const char *xml = iio_context_get_xml(ctx);
size_t xml_len = strlen(xml);
char *xml = iio_context_get_xml(ctx);
size_t len, xml_len = strlen(xml);
void *buf;
#if WITH_ZSTD
size_t len;
size_t ret;

len = ZSTD_compressBound(xml_len);
buf = malloc(len);
if (!buf)
if (!buf) {
free(xml);
return NULL;
}

ret = ZSTD_compress(buf, len, xml, xml_len, 3);
free(xml);

if (ZSTD_isError(ret)) {
IIO_WARNING("Unable to compress XML string: %s\n",
ZSTD_getErrorName(xml_len));
Expand All @@ -123,10 +127,7 @@ static void *get_xml_zstd_data(const struct iio_context *ctx, size_t *out_len)

*out_len = ret;
#else
buf = iio_strdup(xml);
if (!buf)
return NULL;

buf = xml;
*out_len = xml_len;
#endif

Expand Down

0 comments on commit 58127c8

Please sign in to comment.