[PATCH] Fix memory leaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2018-03-16 at 19:40 +0900, Jungsup Lee wrote:
> The returned string of the dbus_message_iter_get_signature() must be freed with dbus_free().
> ---
>  src/modules/module-stream-restore.c | 8 +++++++-
>  src/pulsecore/dbus-util.c           | 8 +++++++-
>  src/pulsecore/protocol-dbus.c       | 6 +++++-
>  3 files changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
> index 7ee53340..162d5fef 100644
> --- a/src/modules/module-stream-restore.c
> +++ b/src/modules/module-stream-restore.c
> @@ -346,14 +346,20 @@ static void dbus_entry_free(struct dbus_entry *de) {
>  static int get_volume_arg(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, pa_channel_map *map, pa_cvolume *vol) {
>      DBusMessageIter array_iter;
>      DBusMessageIter struct_iter;
> +    char *signature;
>  
>      pa_assert(conn);
>      pa_assert(msg);
>      pa_assert(iter);
> -    pa_assert(pa_streq(dbus_message_iter_get_signature(iter), "a(uu)"));
>      pa_assert(map);
>      pa_assert(vol);
>  
> +    signature = dbus_message_iter_get_signature(iter);
> +    pa_assert(pa_streq(signature, "a(uu)"));
> +
> +    if (signature)
> +        dbus_free(signature);

pa_streq() expects non-NULL parameters, but signature can be NULL.
Passing NULL to pa_streq() will probably segfault. That's not a
catastrophe, since the assertion would be expected to crash anyway, but
it's still better to crash due to an assertion failure than segfault.

I suggest this:

    pa_assert_se(signature = dbus_message_iter_get_signature(iter));

That way we know that signature is always non-NULL in subsequent code,
and the "if (signature)" check can be removed too.

-- 
Tanu

https://liberapay.com/tanuk
https://www.patreon.com/tanuk


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux