summaryrefslogtreecommitdiff
path: root/libusb/libusbi.h
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2012-06-07 19:27:43 +0100
committerPete Batard <pete@akeo.ie>2012-06-08 23:30:54 +0100
commita983fad006fe39a48517e061bf9f66501ff900be (patch)
tree7077240159f3ae43089f10f7ae642fb56930c88e /libusb/libusbi.h
parentff3259b440b3fa55a48cfb6233341c9ff664894a (diff)
downloadlibusb-a983fad006fe39a48517e061bf9f66501ff900be.tar.gz
All: Prevent memory leaks on realloc failures
* p = realloc(p, new_size) does not free the original buffer in case of a realloc failure. * reallocf() can be used to do so, but is not available on all platforms. * This patch introduces usbi_reallocf() in libusbi.h and use that instead of realloc * Issue and original patch submitted by Moritz Lipp (trac #27)
Diffstat (limited to 'libusb/libusbi.h')
-rw-r--r--libusb/libusbi.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 9de56a1..41a6bf0 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -110,6 +110,14 @@ static inline void list_del(struct list_head *entry)
entry->prev->next = entry->next;
}
+static inline void *usbi_reallocf(void *ptr, size_t size)
+{
+ void *ret = realloc(ptr, size);
+ if (!ret)
+ free(ptr);
+ return ret;
+}
+
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *mptr = (ptr); \
(type *)( (char *)mptr - offsetof(type,member) );})