DragonFlyBSD Kernel Audit
DF-0145 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/kern/vfs_quota.c b/sys/kern/vfs_quota.c
--- a/sys/kern/vfs_quota.c
+++ b/sys/kern/vfs_quota.c
@@ -142,7 +142,25 @@
 void
 vq_done(struct mount *mp)
 {
-	/* TODO: remove the rb trees here */
+	struct ac_unode *unp;
+	struct ac_gnode *gnp;
+
+	if (!vfs_quota_enabled)
+		return;
+
+	/*
+	 * Drain and free the per-uid / per-gid accounting RB-trees that were
+	 * populated by unode_insert()/gnode_insert() (both kmalloc'd from
+	 * M_MOUNT).  Without this every ac_unode/ac_gnode is leaked on unmount.
+	 */
+	while ((unp = RB_ROOT(&mp->mnt_acct.ac_uroot)) != NULL) {
+		RB_REMOVE(ac_utree, &mp->mnt_acct.ac_uroot, unp);
+		kfree(unp, M_MOUNT);
+	}
+	while ((gnp = RB_ROOT(&mp->mnt_acct.ac_groot)) != NULL) {
+		RB_REMOVE(ac_gtree, &mp->mnt_acct.ac_groot, gnp);
+		kfree(gnp, M_MOUNT);
+	}
 }
 
 void