Clean-up: lttngctl: copy string using strdup instead of asprintf
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 2 Nov 2021 19:35:27 +0000 (15:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 2 Nov 2021 19:35:32 +0000 (15:35 -0400)
Use strdup to copy a string instead of using the formatting utilities.
The code of the function is also adapted to follow the coding standards.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I13328737e42a0287a7402761f75c67eef0dbdfdd

src/lib/lttng-ctl/lttng-ctl.c

index 887d268efe909df2a0435fb7e00a16064c502656..83a884c178fa07ad7b70d31b75a14a23df9415dd 100644 (file)
@@ -2614,20 +2614,26 @@ end:
  */
 int lttng_set_tracing_group(const char *name)
 {
+       int ret = 0;
        char *new_group;
+
        if (name == NULL) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
-       if (asprintf(&new_group, "%s", name) < 0) {
-               return -LTTNG_ERR_FATAL;
+       new_group = strdup(name);
+       if (!new_group) {
+               ret = -LTTNG_ERR_FATAL;
+               goto end;
        }
 
        free(tracing_group);
        tracing_group = new_group;
        new_group = NULL;
 
-       return 0;
+end:
+       return ret;
 }
 
 int lttng_calibrate(struct lttng_handle *handle,
This page took 0.025875 seconds and 4 git commands to generate.