Skip to content

Commit

Permalink
firehose: Avoid leaking xml properties
Browse files Browse the repository at this point in the history
In a few places in firehose.c the memory returned from xmlGetProp() is
leaked. Avoid this by freeing it.

Signed-off-by: Bjorn Andersson <[email protected]>
  • Loading branch information
quic-bjorande authored and andersson committed Dec 17, 2024
1 parent aa44721 commit 23c8416
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,24 @@ static xmlNode *firehose_response_parse(const void *buf, size_t len, int *error)
static int firehose_generic_parser(xmlNode *node, void *data)
{
xmlChar *value;
int ret = -EINVAL;

value = xmlGetProp(node, (xmlChar*)"value");
if (!value)
return -EINVAL;

if (xmlStrcmp(node->name, (xmlChar*)"log") == 0) {
printf("LOG: %s\n", value);
return -EAGAIN;
ret = -EAGAIN;
} else if (xmlStrcmp(value, (xmlChar*)"ACK") == 0) {
ret = FIREHOSE_ACK;
} else if (xmlStrcmp(value, (xmlChar*)"NAK") == 0) {
ret = FIREHOSE_NAK;
}

if (xmlStrcmp(value, (xmlChar*)"ACK") == 0)
return FIREHOSE_ACK;
if (xmlStrcmp(value, (xmlChar*)"NAK") == 0)
return FIREHOSE_NAK;
xmlFree(value);

return -EINVAL;
return ret;
}

static int firehose_read(struct qdl_device *qdl, int timeout_ms,
Expand Down Expand Up @@ -213,16 +217,23 @@ static int firehose_configure_response_parser(xmlNode *node, void *data)
size_t max_size;

value = xmlGetProp(node, (xmlChar*)"value");
if (!value)
return -EINVAL;

if (xmlStrcmp(node->name, (xmlChar*)"log") == 0) {
printf("LOG: %s\n", value);
xmlFree(value);
return -EAGAIN;
}

payload = xmlGetProp(node, (xmlChar*)"MaxPayloadSizeToTargetInBytes");
if (!value || !payload)
if (!payload) {
xmlFree(value);
return -EINVAL;
}

max_size = strtoul((char*)payload, NULL, 10);
xmlFree(payload);

/*
* When receiving an ACK the remote may indicate that we should attempt
Expand All @@ -234,9 +245,11 @@ static int firehose_configure_response_parser(xmlNode *node, void *data)
return -EINVAL;

max_size = strtoul((char*)payload, NULL, 10);
xmlFree(payload);
}

*(size_t*)data = max_size;
xmlFree(value);

return FIREHOSE_ACK;
}
Expand Down

0 comments on commit 23c8416

Please sign in to comment.