From 0b3f40f37183df18eb70255a9cc96d57d96b9a3e Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Thu, 28 Jan 2010 19:56:05 -0500 Subject: [PATCH] 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 --- lib/netdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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; -- 2.30.2