summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_unit.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2004-10-25 12:27:03 +0000
committerphk <phk@FreeBSD.org>2004-10-25 12:27:03 +0000
commit064b8877b84ec93ec3a85a6146366249ecb3e94e (patch)
treedf846a50f2f7662770b1b29b9b37b50997646276 /sys/kern/subr_unit.c
parent4feceb845b7fb3f7aa4b129ace24799cd41d7683 (diff)
downloadFreeBSD-src-064b8877b84ec93ec3a85a6146366249ecb3e94e.zip
FreeBSD-src-064b8877b84ec93ec3a85a6146366249ecb3e94e.tar.gz
Add delete_unrhdr() function.
It will fail fatally if all allocated numbers have not been returned first.
Diffstat (limited to 'sys/kern/subr_unit.c')
-rw-r--r--sys/kern/subr_unit.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/sys/kern/subr_unit.c b/sys/kern/subr_unit.c
index aa4569e..10a9b35 100644
--- a/sys/kern/subr_unit.c
+++ b/sys/kern/subr_unit.c
@@ -216,6 +216,18 @@ new_unrhdr(u_int low, u_int high)
return (uh);
}
+void
+delete_unrhdr(struct unrhdr *uh)
+{
+
+ KASSERT(uh->busy == 0, ("unrhdr has %u allocations", uh->busy));
+
+ /* We should have a single un only */
+ delete_unr(uh, TAILQ_FIRST(&uh->head));
+ KASSERT(uh->alloc == 0, ("UNR memory leak in delete_unrhdr"));
+ Free(uh);
+}
+
/*
* See if a given unr should be collapsed with a neighbor
*/
@@ -567,7 +579,7 @@ int
main(int argc __unused, const char **argv __unused)
{
struct unrhdr *uh;
- int i, x;
+ int i, x, m;
char a[NN];
uh = new_unrhdr(0, NN - 1);
@@ -577,7 +589,7 @@ main(int argc __unused, const char **argv __unused)
fprintf(stderr, "sizeof(struct unr) %d\n", sizeof (struct unr));
fprintf(stderr, "sizeof(struct unrhdr) %d\n", sizeof (struct unrhdr));
x = 1;
- for (;;) {
+ for (m = 0; m < NN; m++) {
i = random() % NN;
if (a[i]) {
printf("F %u\n", i);
@@ -592,6 +604,11 @@ main(int argc __unused, const char **argv __unused)
print_unrhdr(uh);
check_unrhdr(uh, __LINE__);
}
+ for (i = 0; i < NN; i++)
+ if (a[i])
+ free_unr(uh, i);
+ print_unrhdr(uh);
+ delete_unrhdr(uh);
return (0);
}
#endif
OpenPOWER on IntegriCloud