[PATCH] config-parser: Check malloc returns

Marek Chalupa mchqwerty at gmail.com
Fri Jan 15 00:33:21 PST 2016


Hi

On 01/13/2016 09:30 PM, Bryce Harrington wrote:
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> ---
>   shared/config-parser.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/shared/config-parser.c b/shared/config-parser.c
> index a50773b..137a9f1 100644
> --- a/shared/config-parser.c
> +++ b/shared/config-parser.c
> @@ -312,6 +312,8 @@ config_add_section(struct weston_config *config, const char *name)
>   	struct weston_config_section *section;
>
>   	section = malloc(sizeof *section);
> +	if (section == NULL)
> +		return NULL;
>   	section->name = strdup(name);

The strdup can fail too

>   	wl_list_init(&section->entry_list);
>   	wl_list_insert(config->section_list.prev, &section->link);
> @@ -326,6 +328,8 @@ section_add_entry(struct weston_config_section *section,
>   	struct weston_config_entry *entry;
>
>   	entry = malloc(sizeof *entry);
> +	if (entry == NULL)
> +		return NULL;
>   	entry->key = strdup(key);
>   	entry->value = strdup(value);

The same

>   	wl_list_insert(section->entry_list.prev, &entry->link);
>

Cheers,
Marek


More information about the wayland-devel mailing list