⬢ DragonFlyBSD Kernel Audit
DF-5590 / fix.diff
← back to finding ↓ download raw
--- a/sys/bus/isa/vga_isa.c
+++ b/sys/bus/isa/vga_isa.c
@@ -133,6 +133,8 @@
 isavga_attach(device_t dev)
 {
 	vga_softc_t *sc;
+	struct resource *iores;
+	struct resource *memres;
 	int unit;
 	int rid;
 	int error;
@@ -141,23 +143,30 @@
 	sc = device_get_softc(dev);
 
 	rid = 0;
-	bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
-			   0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
+	iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
+				   0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
 	rid = 0;
-	bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
-			   0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
+	memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
+				    0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
 
 	error = vga_attach_unit(unit, sc, device_get_flags(dev));
-	if (error)
+	if (error) {
+		if (iores != NULL)
+			bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
+		if (memres != NULL)
+			bus_release_resource(dev, SYS_RES_MEMORY, 0, memres);
 		return error;
+	}
 
 #ifdef FB_INSTALL_CDEV
 	/* attach a virtual frame buffer device */
 	sc->devt = make_dev(&isavga_ops, VGA_MKMINOR(unit), 0, 0, 02660, "vga%x", VGA_MKMINOR(unit));
 	reference_dev(sc->devt);
 	error = fb_attach(sc->devt, sc->adp);
-	if (error)
+	if (error) {
+		destroy_dev(sc->devt);
 		return error;
+	}
 #endif /* FB_INSTALL_CDEV */
 
 	if (bootverbose)