Fix: sessiond: fix memory leak in receive_lttng_trigger
[lttng-tools.git] / src / bin / lttng-sessiond / event-notifier-error-accounting.c
index 6837fe8f34de7ece5b734b4aeeaf168f19f9ac3f..aee82742a80ba9412f641632081fae402b3159b3 100644 (file)
@@ -223,11 +223,11 @@ struct error_account_entry *create_uid_accounting_entry(
                cpu_counter_fds[i] = -1;
        }
 
-       cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(**cpu_counters));
+       cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
        if (!cpu_counters) {
                PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
-                               entry->nr_counter_cpu_fds * sizeof(**cpu_counters));
+                               entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
                ret = -1;
                goto error_counter_cpus_alloc;
        }
@@ -438,7 +438,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app)
                goto error_send_counter_data;
        }
 
-       cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data));
+       cpu_counters = zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
        if (!cpu_counters) {
                PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
@@ -481,7 +481,6 @@ event_notifier_error_accounting_register_app(struct ust_app *app)
        cpu_counters = NULL;
        goto end;
 
-error_allocate_cpu_counters:
 error_send_cpu_counter_data:
 error_duplicate_cpu_counter:
        /* Teardown any duplicated cpu counters. */
@@ -498,6 +497,9 @@ error_duplicate_cpu_counter:
                free(cpu_counters[i]);
        }
 
+       free(cpu_counters);
+
+error_allocate_cpu_counters:
 error_send_counter_data:
        ustctl_release_object(-1, new_counter);
        free(new_counter);
@@ -1003,6 +1005,7 @@ void event_notifier_error_accounting_unregister_event_notifier(
        lttng_ht_lookup(error_counter_indexes_ht, &tracer_token, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (node) {
+               int del_ret;
                struct index_ht_entry *index_entry = caa_container_of(
                                node, typeof(*index_entry), node);
                enum lttng_index_allocator_status index_alloc_status;
@@ -1023,7 +1026,8 @@ void event_notifier_error_accounting_unregister_event_notifier(
                        /* Don't exit, perform the rest of the clean-up. */
                }
 
-               lttng_ht_del(error_counter_indexes_ht, &iter);
+               del_ret = lttng_ht_del(error_counter_indexes_ht, &iter);
+               assert(!del_ret);
                call_rcu(&index_entry->rcu_head, free_index_ht_entry);
        }
 
This page took 0.024893 seconds and 4 git commands to generate.