Wouter van Gulik wrote:
> On 05/20/2012 12:00 PM, openwrt-devel-requ...@lists.openwrt.org wrote:
> >Message: 3
> >Date: Sat, 19 May 2012 22:28:57 +0200
> >From: Tobias Diedrich<ranma+open...@tdiedrich.de>
> >To: openwrt-devel@lists.openwrt.org
> >Subject: [OpenWrt-Devel] [PATCH] swconfig: List available switches
> >Message-ID:<20120519202857.gj22...@yumi.tdiedrich.de>
> >Content-Type: text/plain; charset=us-ascii
> >
> >List available switches.
> >
> >As part of the usage message or when the switch name was mistyped,
> >show the user a summary of switch devices available in the system.
> >
> >Signed-off-by: Tobias Diedrich<ranma+open...@tdiedrich.de>
> >
> >
> >Index: package/swconfig/src/cli.c
> >===================================================================
> >--- package/swconfig/src/cli.c       (revision 31813)
> >+++ package/swconfig/src/cli.c       (working copy)
> >@@ -72,9 +72,15 @@
> >  }
> >
> >  static void
> >+print_dev_summary(struct switch_dev *dev)
> >+{
> >+    printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, 
> >dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
> >+}
> >+
> >+static void
> >  list_attributes(struct switch_dev *dev)
> >  {
> >-    printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, 
> >dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
> >+    print_dev_summary(dev);
> >     printf("     --switch\n");
> >     print_attrs(dev->ops);
> >     printf("     --vlan\n");
> >@@ -84,6 +90,21 @@
> >  }
> >
> >  static void
> >+list_switches(void)
> >+{
> >+    struct switch_dev *dev;
> >+    dev = swlib_connect(NULL);
> >+    if (!dev)
> >+            printf("No switches found\n");
> >+    while (dev) {
> >+            struct switch_dev *next = dev->next;
> >+            print_dev_summary(dev);
> >+            swlib_free(dev);
> >+            dev = dev->next;
> >+    }
> This look like a bad idea, free-ing and then getting next... :)

Yeah, that's a typo and should have been "dev = next;".
It worked fine anyway (since it's not multithreaded and only frees
small bits of memory and immediately uses the pointer when the
memory is not overwritten yet), which is why I didn't catch it.

-- 
Tobias                                          PGP: http://8ef7ddba.uguu.de
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to