Fix: Cppcheck memleakOnRealloc mistake
authorDavid Goulet <dgoulet@efficios.com>
Fri, 26 Oct 2012 14:28:21 +0000 (10:28 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 26 Oct 2012 14:28:21 +0000 (10:28 -0400)
Common realloc mistake: "data_buffer" nulled but not freed upon failure.
Common realloc mistake: "tmp" nulled but not freed upon failure

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/ust-app.c

index ebbe5e3930af3ea8b559054fdab8cbdc3d3eab6a..9e6d4bf9fa594dc2f51e93ee2f918360acf994c8 100644 (file)
@@ -1208,9 +1208,12 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr,
        payload_size -= sizeof(struct lttcomm_relayd_metadata_payload);
 
        if (data_buffer_size < data_size) {
+               /* In case the realloc fails, we can free the memory */
+               char *tmp_data_ptr = data_buffer;
                data_buffer = realloc(data_buffer, data_size);
                if (!data_buffer) {
                        ERR("Allocating data buffer");
+                       free(tmp_data_ptr);
                        ret = -1;
                        goto end;
                }
@@ -1482,9 +1485,11 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
 
        data_size = be32toh(data_hdr.data_size);
        if (data_buffer_size < data_size) {
+               char *tmp_data_ptr = data_buffer;
                data_buffer = realloc(data_buffer, data_size);
                if (!data_buffer) {
                        ERR("Allocating data buffer");
+                       free(tmp_data_ptr);
                        ret = -1;
                        goto end_unlock;
                }
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.029992 seconds and 4 git commands to generate.