summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Marie <semarie@cvs.openbsd.org>2015-10-03 13:53:55 +0000
committerSebastien Marie <semarie@cvs.openbsd.org>2015-10-03 13:53:55 +0000
commit24a87ad0e009c56f9fbfa17110bc442f883bd8bf (patch)
tree6726a463d17e23ea9cc5b753a338857dc7d6c561
parent9e8125690013f3a9695b0513f8fab202fe81c6c1 (diff)
correct a memory leak in error code path.
noticed by miod@ ok visa@
-rw-r--r--sys/arch/octeon/dev/octeon_pcibus.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/sys/arch/octeon/dev/octeon_pcibus.c b/sys/arch/octeon/dev/octeon_pcibus.c
index 6cbb86c4b0c..61f9c9341ea 100644
--- a/sys/arch/octeon/dev/octeon_pcibus.c
+++ b/sys/arch/octeon/dev/octeon_pcibus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: octeon_pcibus.c,v 1.16 2014/08/11 19:00:50 miod Exp $ */
+/* $OpenBSD: octeon_pcibus.c,v 1.17 2015/10/03 13:53:54 semarie Exp $ */
/* $NetBSD: bonito_mainbus.c,v 1.11 2008/04/28 20:23:10 martin Exp $ */
/* $NetBSD: bonito_pci.c,v 1.5 2008/04/28 20:23:28 martin Exp $ */
@@ -466,10 +466,9 @@ octeon_pcibus_get_resource_extent(pci_chipset_tag_t pc, int io)
struct extent *ex;
char *exname;
int exnamesz;
- int errors;
exnamesz = 1 + 16 + 4;
- exname = (char *)malloc(exnamesz, M_DEVBUF, M_NOWAIT);
+ exname = malloc(exnamesz, M_DEVBUF, M_NOWAIT);
if (exname == NULL)
return NULL;
snprintf(exname, exnamesz, "%s%s", sc->sc_dev.dv_xname,
@@ -478,34 +477,28 @@ octeon_pcibus_get_resource_extent(pci_chipset_tag_t pc, int io)
ex = extent_create(exname, 0, 0xffffffffffffffff, M_DEVBUF, NULL, 0,
EX_NOWAIT | EX_FILLED);
if (ex == NULL)
- goto out;
+ goto error;
- exname = NULL;
- errors = 0;
if (io) {
- if (extent_free(ex, _OCTEON_PCIBUS_PCIIO_BASE, _OCTEON_PCIBUS_PCIIO_SIZE,
- EX_NOWAIT) != 0)
- errors++;
+ if (extent_free(ex, _OCTEON_PCIBUS_PCIIO_BASE,
+ _OCTEON_PCIBUS_PCIIO_SIZE, EX_NOWAIT) != 0)
+ goto error;
} else {
- if (extent_free(ex, _OCTEON_PCIBUS_PCIMEM_BASE, _OCTEON_PCIBUS_PCIMEM_SIZE,
- EX_NOWAIT) != 0)
- errors++;
- }
-
- if (errors != 0) {
- extent_destroy(ex);
- ex = NULL;
+ if (extent_free(ex, _OCTEON_PCIBUS_PCIMEM_BASE,
+ _OCTEON_PCIBUS_PCIMEM_SIZE, EX_NOWAIT) != 0)
+ goto error;
}
#ifdef DEBUG
extent_print(ex);
#endif
-
-out:
- if (exname != NULL)
- free(exname, M_DEVBUF, 0);
-
return ex;
+
+error:
+ if (ex != NULL)
+ extent_destroy(ex);
+ free(exname, M_DEVBUF, exnamesz);
+ return NULL;
}
/*