summaryrefslogtreecommitdiff
path: root/libgphoto2/gphoto2-camera.c
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/gphoto2-camera.c
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/gphoto2-camera.c')
-rw-r--r--libgphoto2/gphoto2-camera.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/libgphoto2/gphoto2-camera.c b/libgphoto2/gphoto2-camera.c
index b494e18c4..a389b91d1 100644
--- a/libgphoto2/gphoto2-camera.c
+++ b/libgphoto2/gphoto2-camera.c
@@ -326,42 +326,32 @@ gp_camera_new (Camera **camera)
CHECK_NULL (camera);
- *camera = malloc (sizeof (Camera));
- if (!*camera)
- return (GP_ERROR_NO_MEMORY);
- memset (*camera, 0, sizeof (Camera));
-
- (*camera)->functions = malloc(sizeof(CameraFunctions));
- if (!(*camera)->functions) {
- gp_camera_free (*camera);
- return (GP_ERROR_NO_MEMORY);
- }
- memset ((*camera)->functions, 0, sizeof (CameraFunctions));
+ C_MEM (*camera = calloc (1, sizeof (Camera)));
- (*camera)->pc = malloc (sizeof (CameraPrivateCore));
- if (!(*camera)->pc) {
- gp_camera_free (*camera);
- return (GP_ERROR_NO_MEMORY);
+ (*camera)->functions = calloc (1, sizeof (CameraFunctions));
+ (*camera)->pc = calloc (1, sizeof (CameraPrivateCore));
+ if (!(*camera)->functions || !(*camera)->pc) {
+ result = GP_ERROR_NO_MEMORY;
+ goto error;
}
- memset ((*camera)->pc, 0, sizeof (CameraPrivateCore));
(*camera)->pc->ref_count = 1;
/* Create the filesystem */
result = gp_filesystem_new (&(*camera)->fs);
- if (result != GP_OK) {
- gp_camera_free (*camera);
- return (result);
- }
+ if (result < GP_OK)
+ goto error;
/* Create the port */
result = gp_port_new (&(*camera)->port);
- if (result < 0) {
- gp_camera_free (*camera);
- return (result);
- }
+ if (result < GP_OK)
+ goto error;
return(GP_OK);
+
+error:
+ gp_camera_free (*camera);
+ return result;
}
@@ -1616,10 +1606,8 @@ gp_camera_start_timeout (Camera *camera, unsigned int timeout,
* We remember the id here in order to automatically remove
* the timeout on gp_camera_exit.
*/
- ids = realloc (camera->pc->timeout_ids, sizeof (int) *
- (camera->pc->timeout_ids_len + 1));
- if (!ids)
- return (GP_ERROR_NO_MEMORY);
+ C_MEM (ids = realloc (camera->pc->timeout_ids, sizeof (int) *
+ (camera->pc->timeout_ids_len + 1)));
camera->pc->timeout_ids = ids;
id = camera->pc->timeout_start_func (camera, timeout, func,