Re: [PATCH] kexec: socket not released when error situation occur.

2016-09-29 Thread Simon Horman
On Thu, Aug 25, 2016 at 11:15:24AM +0900, YoungHyun Yoo wrote:
> Fix resourceleek in ifdown function when error occur.
> 
> Signed-off-by: YoungHyun Yoo 

Thanks, applied.

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH] kexec: socket not released when error situation occur.

2016-08-25 Thread Baoquan He
On 08/25/16 at 11:15am, YoungHyun Yoo wrote:
> Fix resourceleek in ifdown function when error occur.

resource leak?

> 
> Signed-off-by: YoungHyun Yoo 
> ---
>  kexec/ifdown.c | 26 +++---
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/kexec/ifdown.c b/kexec/ifdown.c
> index 46b7bef..9679ad7 100644
> --- a/kexec/ifdown.c
> +++ b/kexec/ifdown.c
> @@ -1,6 +1,6 @@
>  /*
> - * ifdown.c  Find all network interfaces on the system and
> - *   shut them down.
> + * ifdown.c Find all network interfaces on the system and
> + *  shut them down.
>   *
>   */
>  char *v_ifdown = "@(#)ifdown.c  1.11  02-Jun-1998  miqu...@cistron.nl";
> @@ -20,10 +20,10 @@ char *v_ifdown = "@(#)ifdown.c  1.11  02-Jun-1998  
> miqu...@cistron.nl";
>  #include 
>  
>  /*
> - *   First, we find all shaper devices and down them. Then we
> - *   down all real interfaces. This is because the comment in the
> - *   shaper driver says "if you down the shaper device before the
> - *   attached inerface your computer will follow".
> + *  First, we find all shaper devices and down them. Then we
> + *  down all real interfaces. This is because the comment in the
> + *  shaper driver says "if you down the shaper device before the
> + *  attached inerface your computer will follow".
>   */
>  int ifdown(void)
>  {
> @@ -34,13 +34,13 @@ int ifdown(void)
>   if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
>   fprintf(stderr, "ifdown: ");
>   perror("socket");
> - return -1;
> + goto error;
>   }
>  
>   if ((ifa = if_nameindex()) == NULL) {
>   fprintf(stderr, "ifdown: ");
>   perror("if_nameindex");
> - return -1;
> + goto error;
>   }
>  
>   for (shaper = 1; shaper >= 0; shaper--) {
> @@ -57,18 +57,22 @@ int ifdown(void)
>   if (ioctl(fd, SIOCGIFFLAGS, ) < 0) {
>   fprintf(stderr, "ifdown: shutdown ");
>   perror(ifp->if_name);
> - return -1;
> + goto error;
>   }
>   ifr.ifr_flags &= ~(IFF_UP);
>   if (ioctl(fd, SIOCSIFFLAGS, ) < 0) {
>   fprintf(stderr, "ifdown: shutdown ");
>   perror(ifp->if_name);
> - return -1;
> + goto error;
>   }
>  
>   }
>   }
> - close(fd);
>  
> + close(fd);
>   return 0;
> +
> +error:
> + close(fd);
> + return -1;
>  }
> -- 
> 2.9.0.GIT
> 
> 
> ___
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


[PATCH] kexec: socket not released when error situation occur.

2016-08-24 Thread YoungHyun Yoo
Fix resourceleek in ifdown function when error occur.

Signed-off-by: YoungHyun Yoo 
---
 kexec/ifdown.c | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/kexec/ifdown.c b/kexec/ifdown.c
index 46b7bef..9679ad7 100644
--- a/kexec/ifdown.c
+++ b/kexec/ifdown.c
@@ -1,6 +1,6 @@
 /*
- * ifdown.cFind all network interfaces on the system and
- * shut them down.
+ * ifdown.c Find all network interfaces on the system and
+ *  shut them down.
  *
  */
 char *v_ifdown = "@(#)ifdown.c  1.11  02-Jun-1998  miqu...@cistron.nl";
@@ -20,10 +20,10 @@ char *v_ifdown = "@(#)ifdown.c  1.11  02-Jun-1998  
miqu...@cistron.nl";
 #include 
 
 /*
- * First, we find all shaper devices and down them. Then we
- * down all real interfaces. This is because the comment in the
- * shaper driver says "if you down the shaper device before the
- * attached inerface your computer will follow".
+ *  First, we find all shaper devices and down them. Then we
+ *  down all real interfaces. This is because the comment in the
+ *  shaper driver says "if you down the shaper device before the
+ *  attached inerface your computer will follow".
  */
 int ifdown(void)
 {
@@ -34,13 +34,13 @@ int ifdown(void)
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
fprintf(stderr, "ifdown: ");
perror("socket");
-   return -1;
+   goto error;
}
 
if ((ifa = if_nameindex()) == NULL) {
fprintf(stderr, "ifdown: ");
perror("if_nameindex");
-   return -1;
+   goto error;
}
 
for (shaper = 1; shaper >= 0; shaper--) {
@@ -57,18 +57,22 @@ int ifdown(void)
if (ioctl(fd, SIOCGIFFLAGS, ) < 0) {
fprintf(stderr, "ifdown: shutdown ");
perror(ifp->if_name);
-   return -1;
+   goto error;
}
ifr.ifr_flags &= ~(IFF_UP);
if (ioctl(fd, SIOCSIFFLAGS, ) < 0) {
fprintf(stderr, "ifdown: shutdown ");
perror(ifp->if_name);
-   return -1;
+   goto error;
}
 
}
}
-   close(fd);
 
+   close(fd);
return 0;
+
+error:
+   close(fd);
+   return -1;
 }
-- 
2.9.0.GIT


___
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec