Fix: lttng-add-context: context type options possible null dereference
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 27 Jul 2023 16:26:42 +0000 (12:26 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 27 Jul 2023 16:26:42 +0000 (12:26 -0400)
Coverity reports that:
** CID 1518091:  Null pointer dereferences  (FORWARD_NULL)
/src/bin/lttng/commands/add_context.cpp: 820 in destroy_ctx_type(<unnamed>::ctx_type *)(

Free application context options only if type->opt isn't null.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Icc27d04480c4821ed33127f5baf293510cdb314e

src/bin/lttng/commands/add_context.cpp

index 550015f171cb6331b1c92143789df5dba79ea30d..3a0613bd00d6f55c1d40fb5973035c6d90b4213e 100644 (file)
@@ -815,11 +815,11 @@ static void destroy_ctx_type(struct ctx_type *type)
 
        if (type->opt) {
                free(type->opt->symbol);
-       }
 
-       if (type->opt->ctx_type == CONTEXT_APP_CONTEXT) {
-               free(type->opt->u.app_ctx.ctx_name);
-               free(type->opt->u.app_ctx.provider_name);
+               if (type->opt->ctx_type == CONTEXT_APP_CONTEXT) {
+                       free(type->opt->u.app_ctx.ctx_name);
+                       free(type->opt->u.app_ctx.provider_name);
+               }
        }
 
        delete type->opt;
This page took 0.026157 seconds and 4 git commands to generate.