Fix: memcpy used on potentially overlapping regions
[lttng-tools.git] / src / common / trigger.c
index ead0fc259a0eb09af3211df7038aeda00fb28f72..2ef77b2360a2bf8ab1ea80cdf513da2b9d46ce2b 100644 (file)
@@ -46,13 +46,23 @@ struct lttng_trigger *lttng_trigger_create(
                goto end;
        }
 
+       urcu_ref_init(&trigger->ref);
+
+       lttng_condition_get(condition);
        trigger->condition = condition;
+
+       lttng_action_get(action);
        trigger->action = action;
 
 end:
        return trigger;
 }
 
+/*
+ * Note: the lack of reference counting 'get' on the condition object is normal.
+ * This API was exposed as such in 2.11. The client is not expected to call
+ * lttng_condition_destroy on the returned object.
+ */
 struct lttng_condition *lttng_trigger_get_condition(
                struct lttng_trigger *trigger)
 {
@@ -66,6 +76,12 @@ const struct lttng_condition *lttng_trigger_get_const_condition(
        return trigger->condition;
 }
 
+
+/*
+ * Note: the lack of reference counting 'get' on the action object is normal.
+ * This API was exposed as such in 2.11. The client is not expected to call
+ * lttng_action_destroy on the returned object.
+ */
 struct lttng_action *lttng_trigger_get_action(
                struct lttng_trigger *trigger)
 {
@@ -79,15 +95,29 @@ const struct lttng_action *lttng_trigger_get_const_action(
        return trigger->action;
 }
 
-void lttng_trigger_destroy(struct lttng_trigger *trigger)
+static void trigger_destroy_ref(struct urcu_ref *ref)
 {
-       if (!trigger) {
-               return;
-       }
+       struct lttng_trigger *trigger =
+                       container_of(ref, struct lttng_trigger, ref);
+       struct lttng_action *action = lttng_trigger_get_action(trigger);
+       struct lttng_condition *condition =
+                       lttng_trigger_get_condition(trigger);
+
+       assert(action);
+       assert(condition);
+
+       /* Release ownership. */
+       lttng_action_put(action);
+       lttng_condition_put(condition);
 
        free(trigger);
 }
 
+void lttng_trigger_destroy(struct lttng_trigger *trigger)
+{
+       lttng_trigger_put(trigger);
+}
+
 LTTNG_HIDDEN
 ssize_t lttng_trigger_create_from_payload(
                struct lttng_payload_view *src_view,
@@ -149,12 +179,22 @@ ssize_t lttng_trigger_create_from_payload(
                goto error;
        }
 
+       /*
+        * The trigger object owns references to the action and condition
+        * objects.
+        */
+       lttng_condition_put(condition);
+       condition = NULL;
+
+       lttng_action_put(action);
+       action = NULL;
+
        ret = offset;
-end:
-       return ret;
+
 error:
        lttng_condition_destroy(condition);
        lttng_action_destroy(action);
+end:
        return ret;
 }
 
@@ -196,6 +236,22 @@ end:
        return ret;
 }
 
+LTTNG_HIDDEN
+void lttng_trigger_get(struct lttng_trigger *trigger)
+{
+       urcu_ref_get(&trigger->ref);
+}
+
+LTTNG_HIDDEN
+void lttng_trigger_put(struct lttng_trigger *trigger)
+{
+       if (!trigger) {
+               return;
+       }
+
+       urcu_ref_put(&trigger->ref , trigger_destroy_ref);
+}
+
 LTTNG_HIDDEN
 const struct lttng_credentials *lttng_trigger_get_credentials(
                const struct lttng_trigger *trigger)
This page took 0.030102 seconds and 4 git commands to generate.