When using "gcc -O2 -Wall -Werror" to compile libsepol, the following error happens: services.c: In function 'constraint_expr_eval_reason': services.c:820:2: error: 'answer_list' may be used uninitialized in this function [-Werror=maybe-uninitialized] free(answer_list); ^ Indeed, because of a goto statement in constraint_expr_eval_reason function, "free(answer_list)" can be called before answer_list has been initialized. Fix this error by moving the definition of answer_list to the beginning of constraint_expr_eval_reason. --- libsepol/src/services.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 44aa4972a5e3..a1a0b98c73da 100644 --- a/libsepol/src/services.c +++ b/libsepol/src/services.c @@ -417,6 +417,12 @@ static int constraint_expr_eval_reason(context_struct_t *scontext, int rc = 0, x; char *class_buf = NULL; + /* + * The array of expression answer buffer pointers and counter. + */ + char **answer_list = NULL; + int answer_counter = 0; + class_buf = get_class_info(tclass, constraint, xcontext); if (!class_buf) { ERR(NULL, "failed to allocate class buffer"); @@ -686,13 +692,9 @@ mls_ops: expr_counter = 0; /* - * The array of expression answer buffer pointers and counter. * Generate the same number of answer buffer entries as expression * buffers (as there will never be more). */ - char **answer_list; - int answer_counter = 0; - answer_list = malloc(expr_count * sizeof(*answer_list)); if (!answer_list) { ERR(NULL, "failed to allocate answer stack"); -- 2.1.0 _______________________________________________ Selinux mailing list Selinux@xxxxxxxxxxxxx To unsubscribe, send email to Selinux-leave@xxxxxxxxxxxxx. To get help, send an email containing "help" to Selinux-request@xxxxxxxxxxxxx.