[PATCH weston] ivi-shell-transition: check create_layout_transition() return value.

Tanibata, Nobuhiko (ADITJ/SWG) ntanibata at jp.adit-jv.com
Sun Jan 18 18:04:13 PST 2015


Hi,

I basically agree this solution.
When I observe other code in Weston. There are two patterns when error happens in Weston.
- just output error by Weston_log. And then return from the method.
- use wl_resource_post_error and then disconnect client.
Does somebody know which one is better for memory allocate error?

BR,
Nobuhiko Tanibata


> -----Original Message-----
> From: wayland-devel
> [mailto:wayland-devel-bounces at lists.freedesktop.org] On Behalf Of
> Carlos Olmedo Escobar
> Sent: Sunday, January 18, 2015 3:43 AM
> To: wayland-devel at lists.freedesktop.org
> Cc: Carlos Olmedo Escobar
> Subject: [PATCH weston] ivi-shell-transition: check
> create_layout_transition() return value.
> 
> Signed-off-by: Carlos Olmedo Escobar <carlos.olmedo.e at gmail.com>
> ---
>  ivi-shell/ivi-layout-transition.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/ivi-shell/ivi-layout-transition.c
> b/ivi-shell/ivi-layout-transition.c
> index 1e9ee23..904e8d6 100644
> --- a/ivi-shell/ivi-layout-transition.c
> +++ b/ivi-shell/ivi-layout-transition.c
> @@ -328,8 +328,10 @@ create_move_resize_view_transition(
>  			uint32_t duration)
>  {
>  	struct ivi_layout_transition *transition =
> create_layout_transition();
> -	struct move_resize_view_data *data = malloc(sizeof(*data));
> +	if (transition == NULL)
> +		return NULL;
> 
> +	struct move_resize_view_data *data = malloc(sizeof(*data));
>  	if (data == NULL) {
>  		weston_log("%s: memory allocation fails\n", __func__);
>  		return NULL;
> @@ -451,8 +453,10 @@ create_fade_view_transition(
>  			uint32_t duration)
>  {
>  	struct ivi_layout_transition *transition =
> create_layout_transition();
> -	struct fade_view_data *data = malloc(sizeof(*data));
> +	if (transition == NULL)
> +		return NULL;
> 
> +	struct fade_view_data *data = malloc(sizeof(*data));
>  	if (data == NULL) {
>  		weston_log("%s: memory allocation fails\n", __func__);
>  		return NULL;
> @@ -675,8 +679,10 @@ create_move_layer_transition(
>  		uint32_t duration)
>  {
>  	struct ivi_layout_transition *transition =
> create_layout_transition();
> -	struct move_layer_data *data = malloc(sizeof(*data));
> +	if (transition == NULL)
> +		return NULL;
> 
> +	struct move_layer_data *data = malloc(sizeof(*data));
>  	if (data == NULL) {
>  		weston_log("%s: memory allocation fails\n", __func__);
>  		return NULL;
> @@ -819,8 +825,10 @@ ivi_layout_transition_fade_layer(
>  	}
> 
>  	transition = create_layout_transition();
> -	data = malloc(sizeof(*data));
> +	if (transition == NULL)
> +		return;
> 
> +	data = malloc(sizeof(*data));
>  	if (data == NULL) {
>  		weston_log("%s: memory allocation fails\n", __func__);
>  		return;
> --
> 2.1.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list