X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt-context.c;h=634694b968d4c06f6cf5066b684c80efc10d68d9;hb=b64bc438d1c9bbcf241c598ca9f0e00d5770d784;hp=cc9633ac08d63bdd46be0de4d62bf8a89e0fd76b;hpb=2dccf128a59b5353176277d01da4eabcc2086211;p=lttng-modules.git diff --git a/ltt-context.c b/ltt-context.c index cc9633ac..634694b9 100644 --- a/ltt-context.c +++ b/ltt-context.c @@ -4,6 +4,8 @@ * Copyright 2011 (c) - Mathieu Desnoyers * * LTTng trace/channel/event context management. + * + * Dual LGPL v2.1/GPL v2 license. */ #include @@ -28,12 +30,12 @@ struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) if (ctx->nr_fields + 1 > ctx->allocated_fields) { struct lttng_ctx_field *new_fields; - ctx->allocated_fields = min_t(size_t, 1, 2 * ctx->allocated_fields); + ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields); new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL); if (!new_fields) return NULL; if (ctx->fields) - memcpy(new_fields, ctx->fields, ctx->nr_fields); + memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields); kfree(ctx->fields); ctx->fields = new_fields; } @@ -43,12 +45,27 @@ struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) } EXPORT_SYMBOL_GPL(lttng_append_context); +void lttng_remove_context_field(struct lttng_ctx **ctx_p, + struct lttng_ctx_field *field) +{ + struct lttng_ctx *ctx; + + ctx = *ctx_p; + ctx->nr_fields--; + memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field)); +} +EXPORT_SYMBOL_GPL(lttng_remove_context_field); + void lttng_destroy_context(struct lttng_ctx *ctx) { int i; - for (i = 0; i < ctx->nr_fields; i++) - ctx->fields[i].destroy(&ctx->fields[i]); + if (!ctx) + return; + for (i = 0; i < ctx->nr_fields; i++) { + if (ctx->fields[i].destroy) + ctx->fields[i].destroy(&ctx->fields[i]); + } kfree(ctx->fields); kfree(ctx); }