LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

Re: [PATCH] libipvs: Fix memory leak

To: "Ryan O'Hara" <rohara@xxxxxxxxxx>
Subject: Re: [PATCH] libipvs: Fix memory leak
Cc: lvs-devel@xxxxxxxxxxxxxxx, Henrique Mecking <henriquemecking@xxxxxxxxx>, Simon Horman <horms@xxxxxxxxxxxx>
From: Julian Anastasov <ja@xxxxxx>
Date: Sun, 18 Aug 2013 21:18:24 +0300 (EEST)
        Hello,

On Sun, 18 Aug 2013, Ryan O'Hara wrote:

> From: Henrique Mecking <henriquemecking@xxxxxxxxx>
> 
> If malloc fails, free allocated memory before returning NULL.
> 
> Signed-off-by: Ryan O'Hara <rohara@xxxxxxxxxx>

        Looks good to me.

Acked-by: Julian Anastasov <ja@xxxxxx>

> ---
>  libipvs/libipvs.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libipvs/libipvs.c b/libipvs/libipvs.c
> index 2b066d2..1c9e066 100644
> --- a/libipvs/libipvs.c
> +++ b/libipvs/libipvs.c
> @@ -668,8 +668,10 @@ struct ip_vs_get_services *ipvs_get_services(void)
>               return NULL;
>       len = sizeof(*getk) +
>               sizeof(struct ip_vs_service_entry_kern) * 
> ipvs_info.num_services;
> -     if (!(getk = malloc(len)))
> +     if (!(getk = malloc(len))) {
> +             free(get);
>               return NULL;
> +     }
>  
>       ipvs_func = ipvs_get_services;
>       getk->num_services = ipvs_info.num_services;
> @@ -853,8 +855,10 @@ ipvs_nl_dest_failure:
>       }
>  
>       len = sizeof(*dk) + sizeof(struct ip_vs_dest_entry_kern) * 
> svc->num_dests;
> -     if (!(dk = malloc(len)))
> +     if (!(dk = malloc(len))) {
> +             free(d);
>               return NULL;
> +     }
>  
>       dk->fwmark = svc->fwmark;
>       dk->protocol = svc->protocol;
> -- 
> 1.8.1.4

Regards

--
Julian Anastasov <ja@xxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

<Prev in Thread] Current Thread [Next in Thread>