[PATCH weston v2] config-parser: Check malloc and strdup returns

Bryce Harrington bryce at osg.samsung.com
Mon Feb 22 21:32:23 UTC 2016


On Mon, Feb 22, 2016 at 02:47:49PM +0100, Marek Chalupa wrote:
> Hi,
> 
> Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>

Thanks, pushed:
To ssh://git.freedesktop.org/git/wayland/weston
   58b7a15..3f2062c  master -> master
 
> Best,
> Marek
> 
> On 02/18/16 05:46, Bryce Harrington wrote:
> >Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> >---
> >v2: Also check strdup return
> >
> >  shared/config-parser.c | 22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> >
> >diff --git a/shared/config-parser.c b/shared/config-parser.c
> >index a50773b..2256469 100644
> >--- a/shared/config-parser.c
> >+++ b/shared/config-parser.c
> >@@ -312,7 +312,15 @@ 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);
> >+	if (section->name == NULL) {
> >+		free(section);
> >+		return NULL;
> >+	}
> >+
> >  	wl_list_init(&section->entry_list);
> >  	wl_list_insert(config->section_list.prev, &section->link);
> >
> >@@ -326,8 +334,22 @@ 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);
> >+	if (entry->key == NULL) {
> >+		free(entry);
> >+		return NULL;
> >+	}
> >+
> >  	entry->value = strdup(value);
> >+	if (entry->value == NULL) {
> >+		free(entry->key);
> >+		free(entry);
> >+		return NULL;
> >+	}
> >+
> >  	wl_list_insert(section->entry_list.prev, &entry->link);
> >
> >  	return entry;
> >


More information about the wayland-devel mailing list