X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.c;h=c93f93dc9add8333c07470688ae95f14a8f1ec80;hp=fc8728dd21da9b4d68a417323f41fbe0c7a6f225;hb=d7b3776ffb1bef894e7bc4cbfe45c5c2d58b8600;hpb=4e9a468645939ea62541fa802893b928b01888b7 diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index fc8728dd2..c93f93dc9 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -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; }