summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--sys/kern/subr_unit.c21
-rw-r--r--sys/sys/systm.h1
2 files changed, 20 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
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 28e0e4a..b8de519 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -312,6 +312,7 @@ void DELAY(int usec);
*/
struct unrhdr;
struct unrhdr *new_unrhdr(u_int low, u_int high);
+void delete_unrhdr(struct unrhdr *uh);
u_int alloc_unr(struct unrhdr *uh);
void free_unr(struct unrhdr *uh, u_int item);
OpenPOWER on IntegriCloud