Fix: lttng-ctl: use zmalloc(), missing OOM check
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index aae0e4fa5708ed4fd6c6416d5074c867da4bc62f..0041969657e18089c8a957c941924363a752daaf 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <grp.h>
 #include <errno.h>
@@ -225,7 +226,7 @@ int lttng_check_tracing_group(void)
        }
 
        /* Alloc group list of the right size */
-       grp_list = malloc(grp_list_size * sizeof(gid_t));
+       grp_list = zmalloc(grp_list_size * sizeof(gid_t));
        if (!grp_list) {
                perror("malloc");
                goto end;
@@ -445,7 +446,11 @@ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm,
                goto end;
        }
 
-       data = (void*) malloc(size);
+       data = zmalloc(size);
+       if (!data) {
+               ret = -ENOMEM;
+               goto end;
+       }
 
        /* Get payload data */
        ret = recv_data_sessiond(data, size);
@@ -485,7 +490,7 @@ struct lttng_handle *lttng_create_handle(const char *session_name,
                goto end;
        }
 
-       handle = malloc(sizeof(struct lttng_handle));
+       handle = zmalloc(sizeof(struct lttng_handle));
        if (handle == NULL) {
                PERROR("malloc handle");
                goto end;
This page took 0.023483 seconds and 4 git commands to generate.