summaryrefslogtreecommitdiffstats
path: root/lib/idr.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2005-10-23 12:57:18 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-10-23 16:38:39 -0700
commit8d3b35914aa54232b27e6a2b57d84092aadc5e86 (patch)
tree809be8fad6743a751964677e68c5c01af3198e4b /lib/idr.c
parentc0fef676bbd75e711711ed3ff5bebb7bfd1bdb00 (diff)
downloadop-kernel-dev-8d3b35914aa54232b27e6a2b57d84092aadc5e86.zip
op-kernel-dev-8d3b35914aa54232b27e6a2b57d84092aadc5e86.tar.gz
[PATCH] inotify/idr leak fix
Fix a bug which was reported and diagnosed by Stefan Jones <stefan.jones@churchillrandoms.co.uk> IDR trees include a cache of idr_layer objects. There's no way to destroy this cache, so when we discard an overall idr tree we end up leaking some memory. Add and use idr_destroy() for this. v9fs and infiniband also need to use idr_destroy() to avoid leaks. Or, we make the cache global, like radix_tree_preload(). Which is probably better. Later. Cc: Eric Van Hensbergen <ericvh@ericvh.myip.org> Cc: Roland Dreier <rolandd@cisco.com> Cc: Robert Love <rml@novell.com> Cc: John McCutchan <ttb@tentacle.dhs.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib/idr.c')
-rw-r--r--lib/idr.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 6415d05..d4df21d 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -346,6 +346,19 @@ void idr_remove(struct idr *idp, int id)
EXPORT_SYMBOL(idr_remove);
/**
+ * idr_destroy - release all cached layers within an idr tree
+ * idp: idr handle
+ */
+void idr_destroy(struct idr *idp)
+{
+ while (idp->id_free_cnt) {
+ struct idr_layer *p = alloc_layer(idp);
+ kmem_cache_free(idr_layer_cache, p);
+ }
+}
+EXPORT_SYMBOL(idr_destroy);
+
+/**
* idr_find - return pointer for given id
* @idp: idr handle
* @id: lookup key
OpenPOWER on IntegriCloud