diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2014-07-21 20:39:48 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2014-07-21 20:39:48 +0000 |
commit | 0f3f6485c8244000428c928fa0055e52e03c62f7 (patch) | |
tree | 6d94d5338e0b80b221c91b2dc1ea3247d008e9de /libgphoto2/gphoto2-widget.c | |
parent | 9cf5eebe233f882ba1889b28fc975087c5eb4934 (diff) | |
download | libgphoto2-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-widget.c')
-rw-r--r-- | libgphoto2/gphoto2-widget.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libgphoto2/gphoto2-widget.c b/libgphoto2/gphoto2-widget.c index cf0db8d98..06867fd07 100644 --- a/libgphoto2/gphoto2-widget.c +++ b/libgphoto2/gphoto2-widget.c @@ -99,8 +99,7 @@ gp_widget_new (CameraWidgetType type, const char *label, CHECK_NULL (label && widget); - *widget = (CameraWidget*) malloc (sizeof (CameraWidget)); - memset (*widget, 0, sizeof (CameraWidget)); + C_MEM (*widget = calloc (1, sizeof (CameraWidget))); (*widget)->type = type; strcpy ((*widget)->label, label); @@ -483,10 +482,9 @@ gp_widget_append (CameraWidget *widget, CameraWidget *child) return (GP_ERROR_BAD_PARAMETERS); if (widget->children_count) - newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1)); + C_MEM (newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1))); else - newlist = malloc(sizeof(CameraWidget*)); - if (!newlist) return (GP_ERROR_NO_MEMORY); + C_MEM (newlist = malloc(sizeof(CameraWidget*))); widget->children = newlist; widget->children[widget->children_count] = child; widget->children_count += 1; @@ -518,10 +516,9 @@ gp_widget_prepend (CameraWidget *widget, CameraWidget *child) return (GP_ERROR_BAD_PARAMETERS); if (widget->children_count) - newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1)); + C_MEM (newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1))); else - newlist = malloc(sizeof(CameraWidget*)); - if (!newlist) return (GP_ERROR_NO_MEMORY); + C_MEM (newlist = malloc(sizeof(CameraWidget*))); widget->children = newlist; /* Shift down 1 */ @@ -790,11 +787,10 @@ gp_widget_add_choice (CameraWidget *widget, const char *choice) return (GP_ERROR_BAD_PARAMETERS); if (widget->choice_count) { - choices = realloc (widget->choice, sizeof(char*)*(widget->choice_count+1)); + C_MEM (choices = realloc (widget->choice, sizeof(char*)*(widget->choice_count+1))); } else { - choices = malloc (sizeof(char*)); + C_MEM (choices = malloc (sizeof(char*))); } - if (!choices) return (GP_ERROR_NO_MEMORY); widget->choice = choices; widget->choice[widget->choice_count] = strdup(choice); |