From: Jesse Gross Date: Fri, 29 Jan 2010 00:56:05 +0000 (-0500) Subject: netdev: Correctly maintain netdev refcounts even if errors occur. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b3f40f37183df18eb70255a9cc96d57d96b9a3e;p=openvswitch netdev: Correctly maintain netdev refcounts even if errors occur. If an error occured while opening a netdev it would decrement the refcount, even though it was never incremented. Depending on the timing this could result in either an error message or an assertion failure. This workaround simply always increments the refcount before openning a device. A more complete fix already exists in the netdev overhaul in the 'next' branch. NIC-59 --- diff --git a/lib/netdev.c b/lib/netdev.c index 804050fc..f1eb29b5 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -235,6 +235,7 @@ netdev_open(const char *name, int ethertype, struct netdev **netdevp) netdev_obj = shash_find_data(&netdev_obj_shash, name); if (netdev_obj) { + netdev_obj->ref_cnt++; error = netdev_obj->netdev_class->open(name, ethertype, &netdev); } else { /* Default to "system". */ @@ -249,16 +250,14 @@ netdev_open(const char *name, int ethertype, struct netdev **netdevp) * closes its handle. */ error = class->create(name, "system", &empty_args, false); if (!error) { - error = class->open(name, ethertype, &netdev); netdev_obj = shash_find_data(&netdev_obj_shash, name); + netdev_obj->ref_cnt++; + error = class->open(name, ethertype, &netdev); } break; } } } - if (!error) { - netdev_obj->ref_cnt++; - } *netdevp = error ? NULL : netdev; return error;