Cleanup: clarify ownership of excluder
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 15 Dec 2020 14:21:10 +0000 (09:21 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Feb 2021 15:14:42 +0000 (10:14 -0500)
Use a regular pattern for all commands:

If the command callback takes ownership of a pointer or file descriptor,
it sets them to NULL or -1. Therefore, the caller can always try to free
the pointer, or close it if it is greater or equal to 0.

Change-Id: I3947721841222859f4f4eab15ae94856921eb09b
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-events.c
liblttng-ust/lttng-ust-abi.c
liblttng-ust/lttng-ust-comm.c
liblttng-ust/ust-events-internal.h

index 16d75da95b0c265d4785ca61de0513caa29476eb..fbebc338c6f0b7e49760ff6d6f4dc556f009bd36 100644 (file)
@@ -1474,14 +1474,16 @@ int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event
 
 static
 void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
-               struct lttng_ust_excluder_node *excluder)
+               struct lttng_ust_excluder_node **excluder)
 {
-       excluder->enabler = enabler;
-       cds_list_add_tail(&excluder->node, &enabler->excluder_head);
+       (*excluder)->enabler = enabler;
+       cds_list_add_tail(&(*excluder)->node, &enabler->excluder_head);
+       /* Take ownership of excluder */
+       *excluder = NULL;
 }
 
 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler,
-               struct lttng_ust_excluder_node *excluder)
+               struct lttng_ust_excluder_node **excluder)
 {
        _lttng_enabler_attach_exclusion(
                lttng_event_enabler_as_enabler(event_enabler), excluder);
@@ -1536,7 +1538,7 @@ int lttng_event_notifier_enabler_attach_capture_bytecode(
 
 int lttng_event_notifier_enabler_attach_exclusion(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
-               struct lttng_ust_excluder_node *excluder)
+               struct lttng_ust_excluder_node **excluder)
 {
        _lttng_enabler_attach_exclusion(
                lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
index 7490f8b72d22f28435a63475e3900953892d74b8..5063ec6c7c1b14d981ce8fed0ea4d222631cd6cf 100644 (file)
@@ -715,7 +715,7 @@ long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long
                        (struct lttng_ust_bytecode_node *) arg);
        case LTTNG_UST_EXCLUSION:
                return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler,
-                       (struct lttng_ust_excluder_node *) arg);
+                       (struct lttng_ust_excluder_node **) arg);
        case LTTNG_UST_CAPTURE:
                return lttng_event_notifier_enabler_attach_capture_bytecode(
                        event_notifier_enabler,
@@ -1299,7 +1299,7 @@ long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
        case LTTNG_UST_EXCLUSION:
        {
                return lttng_event_enabler_attach_exclusion(enabler,
-                               (struct lttng_ust_excluder_node *) arg);
+                               (struct lttng_ust_excluder_node **) arg);
        }
        default:
                return -EINVAL;
index 7e3bf45036d6f28741a337bd4d9004d3ae192b80..69bce955491db27da8b3c8818da605f9a50a6f5d 100644 (file)
@@ -971,18 +971,13 @@ int handle_message(struct sock_info *sock_info,
                                goto error;
                        }
                }
-               if (ops->cmd) {
+               if (ops->cmd)
                        ret = ops->cmd(lum->handle, lum->cmd,
-                                       (unsigned long) node,
+                                       (unsigned long) &node,
                                        &args, sock_info);
-                       if (ret) {
-                               free(node);
-                       }
-                       /* Don't free exclusion data if everything went fine. */
-               } else {
+               else
                        ret = -ENOSYS;
-                       free(node);
-               }
+               free(node);
                break;
        }
        case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE:
index be5c549c8dccdc7c0f5b3f30eaa158413c64ef0d..73cc22bf511165e1dd5b14913a507da430dc62db 100644 (file)
@@ -151,7 +151,7 @@ int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
  */
 LTTNG_HIDDEN
 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
-               struct lttng_ust_excluder_node *excluder);
+               struct lttng_ust_excluder_node **excluder);
 
 /*
  * Synchronize bytecodes for the enabler and the instance (event or
@@ -242,7 +242,7 @@ int lttng_event_notifier_enabler_attach_capture_bytecode(
 LTTNG_HIDDEN
 int lttng_event_notifier_enabler_attach_exclusion(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
-               struct lttng_ust_excluder_node *excluder);
+               struct lttng_ust_excluder_node **excluder);
 
 LTTNG_HIDDEN
 void lttng_free_event_notifier_filter_runtime(
This page took 0.02895 seconds and 5 git commands to generate.