dect
/
libnl
Archived
13
0
Fork 0

cache: hold a reference to the cache ops while a cache is provided over it

Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
Thomas Graf 2012-11-16 00:27:51 +01:00
parent cb82c2a545
commit 235aa7ff17
1 changed files with 16 additions and 4 deletions

View File

@ -335,6 +335,14 @@ void nl_cache_mngt_provide(struct nl_cache *cache)
BUG(); BUG();
else { else {
nl_cache_get(cache); nl_cache_get(cache);
/*
* Hold a reference to the cache operations to ensure the
* ops don't go away while we use it to store the cache pointer.
*/
if (!ops->co_major_cache)
nl_cache_ops_get(ops);
ops->co_major_cache = cache; ops->co_major_cache = cache;
} }
@ -360,6 +368,7 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
BUG(); BUG();
else if (ops->co_major_cache == cache) { else if (ops->co_major_cache == cache) {
nl_cache_free(ops->co_major_cache); nl_cache_free(ops->co_major_cache);
nl_cache_ops_put(ops);
ops->co_major_cache = NULL; ops->co_major_cache = NULL;
} }
@ -369,12 +378,15 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
struct nl_cache *__nl_cache_mngt_require(const char *name) struct nl_cache *__nl_cache_mngt_require(const char *name)
{ {
struct nl_cache_ops *ops; struct nl_cache_ops *ops;
struct nl_cache *cache = NULL;
ops = nl_cache_ops_lookup(name); ops = nl_cache_ops_lookup_safe(name);
if (ops) if (ops) {
return ops->co_major_cache; cache = ops->co_major_cache;
nl_cache_ops_put(ops);
}
return NULL; return cache;
} }
/** /**