From 11efb0f98f46523c7fb870373ae302b62cccb158 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 13 Dec 2020 03:00:35 -0500 Subject: [PATCH] selector: no NULL deref on error path --- src/lib/selector.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/selector.c b/src/lib/selector.c index 022c48df5..c47009c32 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -247,8 +247,9 @@ ncselector* ncselector_create(ncplane* n, const ncselector_options* opts){ } ncselector* ns = malloc(sizeof(*ns)); if(ns == NULL){ - goto freeitems; + return NULL; } + memset(ns, 0, sizeof(*ns)); if(opts->defidx && opts->defidx >= itemcount){ goto freeitems; } @@ -842,6 +843,10 @@ ncmultiselector* ncmultiselector_create(ncplane* n, const ncmultiselector_option } } ncmultiselector* ns = malloc(sizeof(*ns)); + if(ns == NULL){ + return NULL; + } + memset(ns, 0, sizeof(*ns)); ns->title = opts->title ? strdup(opts->title) : NULL; ns->titlecols = opts->title ? ncstrwidth(opts->title) : 0; ns->secondary = opts->secondary ? strdup(opts->secondary) : NULL;