libipvs: Fix memory leak
PATCH 1/1 libipvs: Fix memory leak
From: Henrique Mecking <[email protected]>
If malloc fails, free allocated memory before returning NULL.
Signed-off-by Ryan O'Hara <[email protected]>
--- libipvs/libipvs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
libipvs/libipvs.c +6 -2
@@ -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;
Signature · 1 line
1.8.1.4
Hello,
Quoted 5 lines · Ryan O'Hara
From: Henrique Mecking <[email protected]>
If malloc fails, free allocated memory before returning NULL.
Signed-off-by Ryan O'Hara <[email protected]>
Looks good to me.
Acked-by Julian Anastasov <[email protected]>
Quoted 34 lines
--- libipvs/libipvs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)libipvs/libipvs.c +6
-2@@ -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;Signature · 1 line
1.8.1.4
Regards
--
Julian Anastasov <[email protected]>
Quoted 7 lines · Julian Anastasov
Hello,
Quoted 2 lines · Ryan O'Hara
From: Henrique Mecking <[email protected]>
Quoted 7 lines
Quoted 3 lines
If malloc fails, free allocated memory before returning NULL.
Signed-off-by Ryan O'Hara <[email protected]>Looks good to me.
Acked-by Julian Anastasov <[email protected]>
Thanks, applied.