- ret = cmd_enable_event(session, &tmp_dom, (char *) default_chan_name,
- &uevent, filter_expression, filter, NULL, wpipe);
+ {
+ struct lttng_filter_bytecode *filter_copy = NULL;
+ char *filter_expression_copy = NULL;
+
+ if (filter) {
+ filter_copy = zmalloc(
+ sizeof(struct lttng_filter_bytecode)
+ + filter->len);
+ if (!filter_copy) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
+ memcpy(filter_copy, filter,
+ sizeof(struct lttng_filter_bytecode)
+ + filter->len);
+ }
+
+ if (filter_expression) {
+ filter_expression_copy =
+ strdup(filter_expression);
+ if (!filter_expression) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error_free_copy;
+ }
+ }
+
+ ret = cmd_enable_event(session, &tmp_dom,
+ (char *) default_chan_name,
+ &uevent, filter_expression_copy,
+ filter_copy, NULL, wpipe);
+ filter_copy = NULL;
+ filter_expression_copy = NULL;
+error_free_copy:
+ free(filter_copy);
+ free(filter_expression_copy);
+ }
+