Add delete_unrhdr() function.
It will fail fatally if all allocated numbers have not been returned first.
This commit is contained in:
parent
7a7386a3e2
commit
e4fea39e9e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136945
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user