From e2d3f9140b1056ea6d23a04ac741f21ba2768136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sun, 7 Jan 2024 17:29:14 +0100 Subject: [PATCH] pw-reserve: fix potential DBusMessage memory leak Our reference to the message must always be dropped, even if `dbus_connection_send()` fails. --- src/tools/reserve.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tools/reserve.c b/src/tools/reserve.c index db78278ae..c28cec1a2 100644 --- a/src/tools/reserve.c +++ b/src/tools/reserve.c @@ -436,6 +436,7 @@ int rd_device_acquire(struct rd_device *d) int rd_device_request_release(struct rd_device *d) { DBusMessage *m = NULL; + int res = 0; if (d->priority <= INT32_MIN) return -EBUSY; @@ -446,16 +447,22 @@ int rd_device_request_release(struct rd_device *d) "RequestRelease")) == NULL) { return -ENOMEM; } - if (!dbus_message_append_args(m, + + if (!dbus_message_append_args(m, DBUS_TYPE_INT32, &d->priority, DBUS_TYPE_INVALID)) { - dbus_message_unref(m); - return -ENOMEM; - } - if (!dbus_connection_send(d->connection, m, NULL)) { - return -EIO; + res = -ENOMEM; + goto exit; } - return 0; + + if (!dbus_connection_send(d->connection, m, NULL)) { + res = -EIO; + goto exit; + } + +exit: + dbus_message_unref(m); + return res; } int rd_device_complete_release(struct rd_device *d, int res)