From 9465e584894eac9503c1ad55c46aac9ee83a26b9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 4 Jul 2017 14:13:15 +0100 Subject: [PATCH 09/19] dbus_message_iter_append_basic: Don't leak signature if appending fd fails Signed-off-by: Simon McVittie --- dbus/dbus-message.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index f66ac1a2..234ddb23 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -2754,20 +2754,22 @@ dbus_message_iter_append_basic (DBusMessageIter *iter, int *fds; dbus_uint32_t u; + ret = FALSE; + /* First step, include the fd in the fd list of this message */ if (!(fds = expand_fd_array(real->message, 1))) - return FALSE; + goto out; *fds = _dbus_dup(*(int*) value, NULL); if (*fds < 0) - return FALSE; + goto out; u = real->message->n_unix_fds; /* Second step, write the index to the fd */ if (!(ret = _dbus_type_writer_write_basic (&real->u.writer, DBUS_TYPE_UNIX_FD, &u))) { _dbus_close(*fds, NULL); - return FALSE; + goto out; } real->message->n_unix_fds += 1; @@ -2793,6 +2795,7 @@ dbus_message_iter_append_basic (DBusMessageIter *iter, ret = _dbus_type_writer_write_basic (&real->u.writer, type, value); } +out: if (!_dbus_message_iter_close_signature (real)) ret = FALSE; -- 2.13.2