From 0e428499a49b2335f4859058739fa2b20f4c410f Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 22 Jan 2013 15:15:08 -0500 Subject: [PATCH] cppcheck: don't check NULL pointer before freeing them Signed-off-by: David Goulet --- src/bin/lttng-sessiond/session.c | 4 +--- src/bin/lttng/commands/create.c | 9 ++------- src/bin/lttng/commands/list.c | 8 ++------ src/bin/lttng/commands/view.c | 4 +--- src/bin/lttng/conf.c | 4 +--- src/common/compat/poll.h | 4 +--- src/common/consumer.c | 23 +++++++---------------- src/common/sessiond-comm/sessiond-comm.c | 4 +--- src/common/uri.c | 5 +---- src/lib/lttng-ctl/lttng-ctl.c | 4 +--- 10 files changed, 18 insertions(+), 51 deletions(-) diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 65e3145a5..6fb6bd360 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -246,9 +246,7 @@ int session_create(char *name, char *path, uid_t uid, gid_t gid) error: error_asprintf: - if (new_session != NULL) { - free(new_session); - } + free(new_session); error_malloc: return ret; diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index d66f0309e..6c7ab786e 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -390,13 +390,8 @@ static int create_session(void) ret = CMD_SUCCESS; error: - if (alloc_url) { - free(alloc_url); - } - - if (traces_path) { - free(traces_path); - } + free(alloc_url); + free(traces_path); free(alloc_path); if (ret < 0) { diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index a6ea6b8c9..8fec91fac 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -474,9 +474,7 @@ static int list_events(const char *channel_name) MSG(""); end: - if (events) { - free(events); - } + free(events); ret = CMD_SUCCESS; error: @@ -821,9 +819,7 @@ int cmd_list(int argc, const char **argv) } end: - if (domains) { - free(domains); - } + free(domains); if (handle) { lttng_destroy_handle(handle); } diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index e3eff22ca..d339282e6 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -361,9 +361,7 @@ static int view_trace(void) } free_sessions: - if (sessions) { - free(sessions); - } + free(sessions); free_error: if (opt_session_name == NULL) { free(session_name); diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c index 995407d03..c1bfcfd45 100644 --- a/src/bin/lttng/conf.c +++ b/src/bin/lttng/conf.c @@ -65,9 +65,7 @@ static FILE *open_config(char *path, const char *mode) } error: - if (file_path) { - free(file_path); - } + free(file_path); return fp; } diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index 49673cd5a..9e889767f 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -43,9 +43,7 @@ extern unsigned int poll_max_size; */ static inline void __lttng_poll_free(void *events) { - if (events) { - free(events); - } + free(events); } /* diff --git a/src/common/consumer.c b/src/common/consumer.c index 15fc9b09f..8bcfa45eb 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -2283,14 +2283,11 @@ void *consumer_thread_data_poll(void *data) */ pthread_mutex_lock(&consumer_data.lock); if (consumer_data.need_update) { - if (pollfd != NULL) { - free(pollfd); - pollfd = NULL; - } - if (local_stream != NULL) { - free(local_stream); - local_stream = NULL; - } + free(pollfd); + pollfd = NULL; + + free(local_stream); + local_stream = NULL; /* allocate for all fds + 1 for the consumer_data_pipe */ pollfd = zmalloc((consumer_data.stream_count + 1) * sizeof(struct pollfd)); @@ -2487,14 +2484,8 @@ void *consumer_thread_data_poll(void *data) } end: DBG("polling thread exiting"); - if (pollfd != NULL) { - free(pollfd); - pollfd = NULL; - } - if (local_stream != NULL) { - free(local_stream); - local_stream = NULL; - } + free(pollfd); + free(local_stream); /* * Close the write side of the pipe so epoll_wait() in diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 799290cbf..d1324d530 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -312,7 +312,5 @@ alloc_error: __attribute__((visibility("hidden"))) void lttcomm_destroy_sock(struct lttcomm_sock *sock) { - if (sock != NULL) { - free(sock); - } + free(sock); } diff --git a/src/common/uri.c b/src/common/uri.c index f64a0de9f..5cc53525f 100644 --- a/src/common/uri.c +++ b/src/common/uri.c @@ -189,10 +189,7 @@ int uri_compare(struct lttng_uri *uri1, struct lttng_uri *uri2) __attribute__((visibility("hidden"))) void uri_free(struct lttng_uri *uri) { - /* Safety check */ - if (uri != NULL) { - free(uri); - } + free(uri); } /* diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 3e532ad60..9ea891e92 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -636,9 +636,7 @@ end: */ void lttng_destroy_handle(struct lttng_handle *handle) { - if (handle) { - free(handle); - } + free(handle); } /* -- 2.34.1