[systemd-devel] [PATCH 3/6] localectl: fix memleak, use _cleanup_strv_free_

Michal Schmidt mschmidt at redhat.com
Thu Oct 25 16:08:45 PDT 2012


Dne 25.10.2012 16:16, Michal Sekletar napsal(a):
> l might contain zero strings, however there is still memory
> allocated for NULL terminator, use _cleanup_strv_free_ instead to
> prevent tiny leak in such case.
> ---
>   src/locale/localectl.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/locale/localectl.c b/src/locale/localectl.c
> index 16700fe..2f0f6ee 100644
> --- a/src/locale/localectl.c
> +++ b/src/locale/localectl.c
> @@ -483,7 +483,8 @@ static int nftw_cb(
>   }
>
>   static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
> -        char **l, **i;
> +        char _cleanup_strv_free_ **l;
> +        char **i;
>
>           keymaps = set_new(string_hash_func, string_compare_func);
>           if (!keymaps)
>

When using _cleanup_strv_free you must initialize l to NULL.
Also you forgot that there's one explicit strv_free(l) in the function. 
That would result in freeing it twice.

Michal



More information about the systemd-devel mailing list