Add hashtable destroy
[lttng-tools.git] / liblttngctl / lttngctl.c
index 42f3ad2ae9950729c3c53922c759d53173d59ee5..d0ba52bbf419d8a8b026a4316e3212271f0aef44 100644 (file)
  */
 
 #define _GNU_SOURCE
-#include <errno.h>
 #include <grp.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#include <lttng/lttng.h>
-
 #include <lttng-sessiond-comm.h>
-#include "lttngerr.h"
-#include "lttng-share.h"
+#include <lttng-share.h>
+#include <lttng/lttng.h>
+#include <lttngerr.h>
 
 /* Socket to session daemon for communication */
 static int sessiond_socket;
@@ -153,6 +152,10 @@ static int check_tracing_group(const char *grp_name)
 
        /* Alloc group list of the right size */
        grp_list = malloc(grp_list_size * sizeof(gid_t));
+       if (!grp_list) {
+               ret = -1;
+               goto end;
+       }
        grp_id = getgroups(grp_list_size, grp_list);
        if (grp_id < -1) {
                perror("getgroups");
@@ -331,6 +334,10 @@ static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
 
        size = llm.data_size;
        if (size == 0) {
+               /* If client free with size 0 */
+               if (buf != NULL) {
+                       *buf = NULL;
+               }
                ret = 0;
                goto end;
        }
@@ -344,6 +351,16 @@ static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
                goto end;
        }
 
+       /*
+        * Extra protection not to dereference a NULL pointer. If buf is NULL at
+        * this point, an error is returned and data is freed.
+        */
+       if (buf == NULL) {
+               ret = -1;
+               free(data);
+               goto end;
+       }
+
        *buf = data;
        ret = size;
 
@@ -479,7 +496,7 @@ int lttng_enable_event(struct lttng_handle *handle,
 {
        struct lttcomm_session_msg lsm;
 
-       if (!handle) {
+       if (!handle || ev == NULL) {
                return -1;
        }
 
@@ -493,12 +510,12 @@ int lttng_enable_event(struct lttng_handle *handle,
 
        copy_lttng_domain(&lsm.domain, &handle->domain);
 
-       if (ev) {
+       if (ev->name[0] != '\0') {
                lsm.cmd_type = LTTNG_ENABLE_EVENT;
-               memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
        } else {
                lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
        }
+       memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
 
        copy_string(lsm.session.name, handle->session_name,
                        sizeof(lsm.session.name));
@@ -528,7 +545,7 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name,
 
        copy_lttng_domain(&lsm.domain, &handle->domain);
 
-       if (name == NULL) {
+       if (name != NULL) {
                copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name));
                lsm.cmd_type = LTTNG_DISABLE_EVENT;
        } else {
@@ -623,7 +640,7 @@ int lttng_list_tracepoints(struct lttng_handle *handle,
 /*
  *  Return a human readable string of code
  */
-const char *lttng_get_readable_code(int code)
+const char *lttng_strerror(int code)
 {
        if (code > -LTTCOMM_OK) {
                return "Ended with errors";
This page took 0.024191 seconds and 4 git commands to generate.