]> granicus.if.org Git - libnl/commitdiff
cache: Hold cache reference while a cache is being provided
authorThomas Graf <tgraf@suug.ch>
Thu, 15 Nov 2012 19:49:33 +0000 (20:49 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 15 Nov 2012 19:49:33 +0000 (20:49 +0100)
Signed-off-by: Thomas Graf <tgraf@suug.ch>
lib/cache_mngt.c

index fa1ac22c67750fa8fc18734d55ec936a875a58fa..540c5c169e099b813540e0bb93ae8a425a6e671b 100644 (file)
@@ -217,8 +217,10 @@ void nl_cache_mngt_provide(struct nl_cache *cache)
        ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
        if (!ops)
                BUG();
-       else
+       else {
+               nl_cache_get(cache);
                ops->co_major_cache = cache;
+       }
 }
 
 /**
@@ -236,8 +238,10 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
        ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
        if (!ops)
                BUG();
-       else if (ops->co_major_cache == cache)
+       else if (ops->co_major_cache == cache) {
+               nl_cache_free(ops->co_major_cache);
                ops->co_major_cache = NULL;
+       }
 }
 
 struct nl_cache *__nl_cache_mngt_require(const char *name)