mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-28 15:30:09 +01:00
dbus_message_iter_get_signature: Fix two memory leaks on OOM
Previously, `retstr` would not be freed when `_dbus_string_append_len()` or `_dbus_string_steal_data()` failed. Fix those by: * jumping to `_dbus_string_free()` when `_dbus_string_append_len()` fails * ignoring the return value of `_dbus_string_free()`. The latter works because in case of failure, `ret` will be set to NULL by `_dbus_string_steal_data()`. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
This commit is contained in:
parent
a841b8ec8f
commit
b5a87e214f
1 changed files with 8 additions and 4 deletions
|
|
@ -2293,7 +2293,7 @@ dbus_message_iter_get_signature (DBusMessageIter *iter)
|
|||
{
|
||||
const DBusString *sig;
|
||||
DBusString retstr;
|
||||
char *ret;
|
||||
char *ret = NULL;
|
||||
int start, len;
|
||||
DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
|
||||
|
||||
|
|
@ -2307,9 +2307,13 @@ dbus_message_iter_get_signature (DBusMessageIter *iter)
|
|||
if (!_dbus_string_append_len (&retstr,
|
||||
_dbus_string_get_const_data (sig) + start,
|
||||
len))
|
||||
return NULL;
|
||||
if (!_dbus_string_steal_data (&retstr, &ret))
|
||||
return NULL;
|
||||
goto oom;
|
||||
|
||||
/* This is correct whether it succeeds or fails: on success it sets `ret`,
|
||||
* and on failure it leaves `ret` set to NULL. */
|
||||
_dbus_string_steal_data (&retstr, &ret);
|
||||
|
||||
oom:
|
||||
_dbus_string_free (&retstr);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue