alfred: avoid leak of dataset on buffer allocation
PATCH 1/1 alfred: avoid leak of dataset on buffer allocation
When the buffer of a new dataset cannot be allocated, then the dataset is not yet attached to the hash (and doesn't have a buffer associated). In this, case the data handler functions would just jump out of the function and leak the heap allocated dataset.
The newly allocated dataset must therefore be freed before exiting functions.
Signed-off-by Sven Eckelmann <[email protected]>
--- recv.c | 6 +++++- unix_sock.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)
recv.c +5 -1
@@ -79,8 +79,12 @@ static int finish_alfred_push_data(struct globals *globals,memcmp (dataset->buf, data->data, data_len) !=0 ; buf =malloc (data_len); -if (!buf) +if (!buf) { +if (new_entry_created) +free (dataset); + goto err; + }/* free old buffer */ if (dataset->buf) {
unix_sock.c +5 -1
@@ -195,8 +195,12 @@ static int unix_sock_add_data(struct globals *globals,memcmp (dataset->buf, data->data, data_len) !=0 ; buf =malloc (data_len); -if (!buf) +if (!buf) { +if (new_entry_created) +free (dataset); + goto err; + }/* free old buffer */ if (dataset->buf) {
---
base-commit: de0e9bae7b5bf68406d26224d56268901ebb0480
change-id: 20260906-error-leak-c19fcc49eb5e
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>