free in slot_detach() memory allocated in slot_attach()

This commit is contained in:
Alexandre Ratchov 2012-11-11 00:01:52 +01:00
parent b55ceed719
commit b04a783fd8
1 changed files with 17 additions and 22 deletions

View File

@ -1500,22 +1500,15 @@ slot_new(struct dev *d, char *who, struct slotops *ops, void *arg, int mode)
strlcpy(name, "noname", SLOT_NAMEMAX); strlcpy(name, "noname", SLOT_NAMEMAX);
/* /*
* find the instance number of the control name * find the first unused "unit" number for this name
*/ */
for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) { for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
if (s->ops == NULL) if (s->ops == NULL)
continue; continue;
if (strcmp(s->name, name) == 0) if (strcmp(s->name, name) == 0)
umap |= (1 << s->unit); umap |= (1 << s->unit);
} }
for (unit = 0; ; unit++) { for (unit = 0; ; unit++) {
if (unit == DEV_NSLOT) {
if (log_level >= 1) {
log_puts(name);
log_puts(": has too many instances\n");
}
return NULL;
}
if ((umap & (1 << unit)) == 0) if ((umap & (1 << unit)) == 0)
break; break;
} }
@ -1914,8 +1907,20 @@ slot_detach(struct slot *s)
panic(); panic();
} }
#endif #endif
} }
*ps = s->next; *ps = s->next;
if (s->mode & MODE_RECMASK) {
if (s->sub.encbuf)
xfree(s->sub.encbuf);
if (s->sub.resampbuf)
xfree(s->sub.resampbuf);
}
if (s->mode & MODE_PLAY) {
if (s->mix.decbuf)
xfree(s->mix.decbuf);
if (s->mix.resampbuf)
xfree(s->mix.resampbuf);
}
} }
void void
@ -1934,13 +1939,8 @@ slot_stop(struct slot *s)
} else } else
s->pstate = SLOT_INIT; s->pstate = SLOT_INIT;
} }
if (s->mode & MODE_RECMASK) { if (s->mode & MODE_RECMASK)
abuf_done(&s->sub.buf); abuf_done(&s->sub.buf);
if (s->sub.encbuf)
xfree(s->sub.encbuf);
if (s->sub.resampbuf)
xfree(s->sub.resampbuf);
}
if (s->pstate == SLOT_READY) { if (s->pstate == SLOT_READY) {
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 3) { if (log_level >= 3) {
@ -1948,13 +1948,8 @@ slot_stop(struct slot *s)
log_puts(": not drained (blocked by mmc)\n"); log_puts(": not drained (blocked by mmc)\n");
} }
#endif #endif
if (s->mode & MODE_PLAY) { if (s->mode & MODE_PLAY)
abuf_done(&s->mix.buf); abuf_done(&s->mix.buf);
if (s->mix.decbuf)
xfree(s->mix.decbuf);
if (s->mix.resampbuf)
xfree(s->mix.resampbuf);
}
s->ops->eof(s->arg); s->ops->eof(s->arg);
s->pstate = SLOT_INIT; s->pstate = SLOT_INIT;
} else { } else {