summaryrefslogtreecommitdiff
path: root/libgphoto2_port/usb
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2014-07-21 20:39:48 +0000
committerMarcus Meissner <marcus@jet.franken.de>2014-07-21 20:39:48 +0000
commit0f3f6485c8244000428c928fa0055e52e03c62f7 (patch)
tree6d94d5338e0b80b221c91b2dc1ea3247d008e9de /libgphoto2_port/usb
parent9cf5eebe233f882ba1889b28fc975087c5eb4934 (diff)
downloadlibgphoto2-0f3f6485c8244000428c928fa0055e52e03c62f7.tar.gz
From: Axel Waggershauser <awagger@web.de>
here is a patch for (mostly) consistent usage of a generalized C_MEM macro for checking the return values of memory allocating functions, i.e. malloc, calloc, realloc and strdup. It is the C_MEM from libusb1.c, moved to gphoto2-port-log.h. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15096 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port/usb')
-rw-r--r--libgphoto2_port/usb/libusb.c8
-rw-r--r--libgphoto2_port/usb/usb-os2.c5
2 files changed, 5 insertions, 8 deletions
diff --git a/libgphoto2_port/usb/libusb.c b/libgphoto2_port/usb/libusb.c
index 5bdeb4ed8..60a9db444 100644
--- a/libgphoto2_port/usb/libusb.c
+++ b/libgphoto2_port/usb/libusb.c
@@ -216,10 +216,7 @@ gp_port_library_list (GPPortInfoList *list)
static int gp_port_usb_init (GPPort *port)
{
- port->pl = malloc (sizeof (GPPortPrivateLibrary));
- if (!port->pl)
- return (GP_ERROR_NO_MEMORY);
- memset (port->pl, 0, sizeof (GPPortPrivateLibrary));
+ C_MEM (port->pl = calloc (1, sizeof (GPPortPrivateLibrary)));
port->pl->config = port->pl->interface = port->pl->altsetting = -1;
@@ -1268,10 +1265,9 @@ gp_port_library_operations (void)
{
GPPortOperations *ops;
- ops = malloc (sizeof (GPPortOperations));
+ ops = calloc (1, sizeof (GPPortOperations));
if (!ops)
return (NULL);
- memset (ops, 0, sizeof (GPPortOperations));
ops->init = gp_port_usb_init;
ops->exit = gp_port_usb_exit;
diff --git a/libgphoto2_port/usb/usb-os2.c b/libgphoto2_port/usb/usb-os2.c
index bce14df46..f5c462240 100644
--- a/libgphoto2_port/usb/usb-os2.c
+++ b/libgphoto2_port/usb/usb-os2.c
@@ -62,8 +62,9 @@ gp_port_operations *gp_port_library_operations () {
gp_port_operations *ops;
- ops = (gp_port_operations*)malloc(sizeof(gp_port_operations));
- memset(ops, 0, sizeof(gp_port_operations));
+ ops = calloc(1, sizeof(gp_port_operations));
+ if (!ops)
+ return NULL;
ops->init = gp_port_usb_init;
ops->exit = gp_port_usb_exit;