[PATCH] client: fix a strdup memory leak

Kristian Høgsberg krh at bitplanet.net
Tue Dec 13 07:03:25 PST 2011


On Tue, Dec 13, 2011 at 7:53 AM, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> Memory leak found by valgrinding simple-shm client.
> struct wl_global::interface is a strdup()'d string that was never freed.
>
> Make a function for freeing a wl_global, and use it.

Thanks.  Pushed with a minor edit to name the wl_global destructor
wl_global_destroy like other destructors.

> Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
> ---
>  src/wayland-client.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index 22244f8..bf9735c 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -252,6 +252,14 @@ display_handle_global(void *data,
>  }
>
>  static void
> +free_global(struct wl_global *global)
> +{
> +       wl_list_remove(&global->link);
> +       free(global->interface);
> +       free(global);
> +}
> +
> +static void
>  display_handle_global_remove(void *data,
>                              struct wl_display *display, uint32_t id)
>  {
> @@ -259,8 +267,7 @@ display_handle_global_remove(void *data,
>
>        wl_list_for_each(global, &display->global_list, link)
>                if (global->id == id) {
> -                       wl_list_remove(&global->link);
> -                       free(global);
> +                       free_global(global);
>                        break;
>                }
>  }
> @@ -394,7 +401,7 @@ wl_display_destroy(struct wl_display *display)
>        wl_map_release(&display->objects);
>        wl_list_for_each_safe(global, gnext,
>                              &display->global_list, link)
> -               free(global);
> +               free_global(global);
>        wl_list_for_each_safe(listener, lnext,
>                              &display->global_listener_list, link)
>                free(listener);
> --
> 1.7.3.4
>


More information about the wayland-devel mailing list