On 15/11/2014 11:06, arei.gong...@huawei.com wrote:
> From: Gonglei <arei.gong...@huawei.com>
> 
> If 'i != index' for all acl->entries, variable
> entry leaks the storage it points to.
> 
> Signed-off-by: Gonglei <arei.gong...@huawei.com>
> ---
>  util/acl.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/util/acl.c b/util/acl.c
> index 938b7ae..571d686 100644
> --- a/util/acl.c
> +++ b/util/acl.c
> @@ -132,7 +132,6 @@ int qemu_acl_insert(qemu_acl *acl,
>                      const char *match,
>                      int index)
>  {
> -    qemu_acl_entry *entry;
>      qemu_acl_entry *tmp;
>      int i = 0;
>  
> @@ -142,13 +141,14 @@ int qemu_acl_insert(qemu_acl *acl,
>          return qemu_acl_append(acl, deny, match);
>      }
>  
> -    entry = g_malloc(sizeof(*entry));
> -    entry->match = g_strdup(match);
> -    entry->deny = deny;
> -
>      QTAILQ_FOREACH(tmp, &acl->entries, next) {
>          i++;
>          if (i == index) {
> +            qemu_acl_entry *entry;
> +            entry = g_malloc(sizeof(*entry));
> +            entry->match = g_strdup(match);
> +            entry->deny = deny;
> +
>              QTAILQ_INSERT_BEFORE(tmp, entry, next);
>              acl->nentries++;
>              break;
> 

This should never happen, but the patch doesn't hurt either.

Paolo

Reply via email to