Patch from Jeff Johnson <jbj@redhat.com> to fix `netstat -c'
authorPhil Blundell <philb@gnu.org>
Wed, 28 Jul 1999 21:53:34 +0000 (21:53 +0000)
committerPhil Blundell <philb@gnu.org>
Wed, 28 Jul 1999 21:53:34 +0000 (21:53 +0000)
fd leak.

include/interface.h
lib/interface.c
netstat.c

index 67076c6..133b7d6 100644 (file)
@@ -65,6 +65,7 @@ struct interface {
 extern int if_fetch(struct interface *ife);
 
 extern int for_all_interfaces(int (*)(struct interface *, void *), void *);
+extern int free_interface_list(void);
 extern struct interface *lookup_interface(char *name);
 extern int if_readlist(void);
 
index 630e4b9..4baa5df 100644 (file)
@@ -4,7 +4,7 @@
    10/1998 partly rewriten by Andi Kleen to support an interface list.   
    I don't claim that the list operations are efficient @).  
 
-   $Id: interface.c,v 1.4 1999/04/21 09:30:32 philip Exp $
+   $Id: interface.c,v 1.5 1999/07/28 21:53:44 philip Exp $
  */
 
 #include "config.h"
@@ -99,6 +99,16 @@ int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
     return 0;
 }
 
+int free_interface_list(void)
+{
+    struct interface *ife;
+    while ((ife = int_list) != NULL) {
+       int_list = ife->next;
+       free(ife);
+    }
+    return 0;
+}
+
 static int if_readconf(void)
 {
     int numreqs = 30;
index e52b1a5..0e32378 100644 (file)
--- a/netstat.c
+++ b/netstat.c
@@ -6,7 +6,7 @@
  *              NET-3 Networking Distribution for the LINUX operating
  *              system.
  *
- * Version:     $Id: netstat.c,v 1.28 1999/06/12 23:04:15 philip Exp $
+ * Version:     $Id: netstat.c,v 1.29 1999/07/28 21:53:34 philip Exp $
  *
  * Authors:     Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
  *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
@@ -1394,8 +1394,9 @@ static int iface_info(void)
        perror(_("missing interface information"));
        exit(1);
     }
-    if (!flag_cnt)
-        close(skfd);
+    if (flag_cnt)
+       free_interface_list();
+    close(skfd);
     skfd = -1;
 
     return 0;