--- a/sys/dev/sound/pci/emu10k1.c +++ b/sys/dev/sound/pci/emu10k1.c @@ -2075,6 +2075,7 @@ struct ac97_info *codec = NULL; struct sc_info *sc; int i, gotmic; + int inited = 0; char status[SND_STATUSLEN]; sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO); @@ -2115,6 +2116,7 @@ device_printf(dev, "unable to initialize the card\n"); goto bad; } + inited = 1; codec = AC97_CREATE(dev, sc, emu_ac97); if (codec == NULL) goto bad; @@ -2147,6 +2149,9 @@ return 0; bad: + /* Undo emu_init() allocations (ptb_pages, silent_page, mpu401). */ + if (inited) + emu_uninit(sc); if (codec) ac97_destroy(codec); if (sc->reg) bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->reg); if (sc->ih) bus_teardown_intr(dev, sc->irq, sc->ih);