diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-03-21 21:38:56 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2006-03-21 21:38:56 +0000 |
commit | 85be455c5b6ba30e5f6185c30def633c89ff05bc (patch) | |
tree | 8a32cbcadf3856f1274fea72fc617b04c11bbd84 /lib/libusbhid | |
parent | 90c0d62bbb4eb2188b20de1ffb3916a645d5b018 (diff) |
- plug memleak when handling reallocation failure in hid_start()
- avoid NULL dereference while reclaiming memory during error
handling in hid_start()
ok ray dhill
Diffstat (limited to 'lib/libusbhid')
-rw-r--r-- | lib/libusbhid/usage.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/libusbhid/usage.c b/lib/libusbhid/usage.c index cffa7005290..bcfa0d8d1ea 100644 --- a/lib/libusbhid/usage.c +++ b/lib/libusbhid/usage.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usage.c,v 1.8 2006/03/18 03:34:22 dhill Exp $ */ +/* $OpenBSD: usage.c,v 1.9 2006/03/21 21:38:55 jaredy Exp $ */ /* $NetBSD: usage.c,v 1.1 2001/12/28 17:45:27 augustss Exp $ */ /* @@ -153,8 +153,10 @@ hid_start(const char *hidname) len = npagesmax * 5; new = realloc(pages, len * sizeof (struct usage_page)); - if (!new) + if (!new) { + free(n); goto fail; + } pages = new; bzero(pages + npagesmax, npagesmax - npagesmax); @@ -185,14 +187,16 @@ hid_start(const char *hidname) fail: if (f) fclose(f); - for (no = 0; no < npages; no++) { - if (pages[no].name) - free((char *)pages[no].name); - if (pages[no].page_contents) - free((char *)pages[no].page_contents); + if (pages) { + for (no = 0; no < npages; no++) { + if (pages[no].name) + free((char *)pages[no].name); + if (pages[no].page_contents) + free((char *)pages[no].page_contents); + } + free(pages); + pages = NULL; } - free(pages); - pages = NULL; npages = 0; npagesmax = 0; return -1; |