Fix: Cppcheck memleakOnRealloc mistake
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index fc8728dd21da9b4d68a417323f41fbe0c7a6f225..c93f93dc9add8333c07470688ae95f14a8f1ec80 100644 (file)
@@ -1579,12 +1579,15 @@ int ust_app_list_events(struct lttng_event **events)
                                                &uiter)) != -ENOENT) {
                        health_code_update(&health_thread_cmd);
                        if (count >= nbmem) {
+                               /* In case the realloc fails, we free the memory */
+                               void *tmp_ptr = (void *) tmp;
                                DBG2("Reallocating event list from %zu to %zu entries", nbmem,
                                                2 * nbmem);
                                nbmem *= 2;
                                tmp = realloc(tmp, nbmem * sizeof(struct lttng_event));
                                if (tmp == NULL) {
                                        PERROR("realloc ust app events");
+                                       free(tmp_ptr);
                                        ret = -ENOMEM;
                                        goto rcu_error;
                                }
@@ -1654,12 +1657,15 @@ int ust_app_list_event_fields(struct lttng_event_field **fields)
                                                &uiter)) != -ENOENT) {
                        health_code_update(&health_thread_cmd);
                        if (count >= nbmem) {
+                               /* In case the realloc fails, we free the memory */
+                               void *tmp_ptr = (void *) tmp;
                                DBG2("Reallocating event field list from %zu to %zu entries", nbmem,
                                                2 * nbmem);
                                nbmem *= 2;
                                tmp = realloc(tmp, nbmem * sizeof(struct lttng_event_field));
                                if (tmp == NULL) {
                                        PERROR("realloc ust app event fields");
+                                       free(tmp_ptr);
                                        ret = -ENOMEM;
                                        goto rcu_error;
                                }
This page took 0.029089 seconds and 4 git commands to generate.