diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-06 20:43:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-08-06 20:43:13 +0000 |
commit | 70ce44f8da4a9a5ad3cbea4bc8cdb963526e2393 (patch) | |
tree | d4519e23541acab9ed04f76f1d6034127377fbed /sys/dev/usb | |
parent | fc9c86b3f8ae95ba6030429f8549b93f28c89e1a (diff) |
Fix a memleak on error in usb_block_allocmem(); Patrick Latifi
deraadt@ OK
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/usb_mem.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sys/dev/usb/usb_mem.c b/sys/dev/usb/usb_mem.c index 311c37c949c..56489a6a6d4 100644 --- a/sys/dev/usb/usb_mem.c +++ b/sys/dev/usb/usb_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_mem.c,v 1.14 2003/07/08 13:19:09 nate Exp $ */ +/* $OpenBSD: usb_mem.c,v 1.15 2003/08/06 20:43:12 millert Exp $ */ /* $NetBSD: usb_mem.c,v 1.26 2003/02/01 06:23:40 thorpej Exp $ */ /* @@ -143,7 +143,6 @@ usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, p = malloc(sizeof *p, M_USB, M_NOWAIT); if (p == NULL) return (USBD_NOMEM); - *dmap = p; p->tag = tag; p->size = size; @@ -152,12 +151,12 @@ usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, p->segs, sizeof(p->segs)/sizeof(p->segs[0]), &p->nsegs, BUS_DMA_NOWAIT); if (error) - return (USBD_NOMEM); + goto free0; error = bus_dmamem_map(tag, p->segs, p->nsegs, p->size, &p->kaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); if (error) - goto free; + goto free1; error = bus_dmamap_create(tag, p->size, 1, p->size, 0, BUS_DMA_NOWAIT, &p->map); @@ -168,14 +167,18 @@ usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, BUS_DMA_NOWAIT); if (error) goto destroy; + + *dmap = p; return (USBD_NORMAL_COMPLETION); destroy: bus_dmamap_destroy(tag, p->map); unmap: bus_dmamem_unmap(tag, p->kaddr, p->size); -free: +free1: bus_dmamem_free(tag, p->segs, p->nsegs); +free0: + free(p, M_USB); return (USBD_NOMEM); } |