Fix: java application context segmentation fault
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 11 May 2021 14:28:02 +0000 (10:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 11 May 2021 15:35:11 +0000 (11:35 -0400)
Type mismatch for application context private data causes segmentation
faults in the lttng-ust java testsuite.

This can be solved by using the private data provided by the application
context rather than struct lttng_ust_app_ctx, which is not needed
anymore.

This also fixes a memory leak on context add error.

Those issues were introduced by the 2.13 development cycle refactorings.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I19c4e2d0ef6bcb7d4f9c2ffa43a9425661df05c1

src/lib/lttng-ust/lttng-context-provider.c

index 8ef552a2353a8ffd60cef7eede75d792fda85f5a..b411812205e4fa0e980275adda600441fcffe5e0 100644 (file)
@@ -27,12 +27,6 @@ struct lttng_ust_registered_context_provider {
        struct cds_hlist_node node;
 };
 
-struct lttng_ust_app_ctx {
-       char *name;
-       struct lttng_ust_event_field *event_field;
-       struct lttng_ust_type_common *type;
-};
-
 #define CONTEXT_PROVIDER_HT_BITS       12
 #define CONTEXT_PROVIDER_HT_SIZE       (1U << CONTEXT_PROVIDER_HT_BITS)
 struct context_provider_ht {
@@ -125,16 +119,6 @@ end:
        free(reg_provider);
 }
 
-static void destroy_app_ctx(void *priv)
-{
-       struct lttng_ust_app_ctx *app_ctx = (struct lttng_ust_app_ctx *) priv;
-
-       free(app_ctx->name);
-       free(app_ctx->event_field);
-       free(app_ctx->type);
-       free(app_ctx);
-}
-
 /*
  * Called with ust mutex held.
  * Add application context to array of context, even if the application
@@ -150,7 +134,6 @@ int lttng_ust_add_app_context_to_ctx_rcu(const char *name,
        struct lttng_ust_ctx_field new_field = { 0 };
        struct lttng_ust_event_field *event_field = NULL;
        struct lttng_ust_type_common *type = NULL;
-       struct lttng_ust_app_ctx *app_ctx = NULL;
        char *ctx_name;
        int ret;
 
@@ -171,11 +154,6 @@ int lttng_ust_add_app_context_to_ctx_rcu(const char *name,
                ret = -ENOMEM;
                goto error_field_type_alloc;
        }
-       app_ctx = zmalloc(sizeof(struct lttng_ust_app_ctx));
-       if (!app_ctx) {
-               ret = -ENOMEM;
-               goto error_app_ctx_alloc;
-       }
        event_field->name = ctx_name;
        type->type = lttng_ust_type_dynamic;
        event_field->type = type;
@@ -189,25 +167,24 @@ int lttng_ust_add_app_context_to_ctx_rcu(const char *name,
                new_field.get_size = provider->get_size;
                new_field.record = provider->record;
                new_field.get_value = provider->get_value;
+               new_field.priv = provider->priv;
        } else {
                new_field.get_size = lttng_ust_dummy_get_size;
                new_field.record = lttng_ust_dummy_record;
                new_field.get_value = lttng_ust_dummy_get_value;
+               new_field.priv = NULL;
        }
-       new_field.destroy = destroy_app_ctx;
-       new_field.priv = app_ctx;
        /*
         * For application context, add it by expanding
         * ctx array.
         */
        ret = lttng_ust_context_append_rcu(ctx, &new_field);
        if (ret) {
-               destroy_app_ctx(app_ctx);
-               return ret;
+               goto error_append;
        }
        return 0;
 
-error_app_ctx_alloc:
+error_append:
        free(type);
 error_field_type_alloc:
        free(ctx_name);
This page took 0.025727 seconds and 4 git commands to generate.