From: David Goulet Date: Tue, 26 Jul 2011 14:59:20 +0000 (-0400) Subject: Fix safe list iteration X-Git-Tag: v2.0-pre4~6 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=af9737e9006817895374706246dcf3d9efbeb58f;p=lttng-tools.git Fix safe list iteration Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 380aa7d9c..bba8aa64d 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -150,7 +150,7 @@ static void cleanup() { int ret; char *cmd; - struct ltt_session *sess; + struct ltt_session *sess, *stmp; DBG("Cleaning up"); @@ -184,7 +184,7 @@ static void cleanup() pthread_mutex_destroy(&session_list_ptr->lock); /* Cleanup ALL session */ - cds_list_for_each_entry(sess, &session_list_ptr->head, list) { + cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) { teardown_kernel_session(sess); // TODO complete session cleanup (including UST) } diff --git a/ltt-sessiond/session.c b/ltt-sessiond/session.c index 16f137eb0..ff79bf2a9 100644 --- a/ltt-sessiond/session.c +++ b/ltt-sessiond/session.c @@ -156,10 +156,10 @@ struct ltt_session *find_session_by_name(char *name) int destroy_session(char *name) { int found = -1; - struct ltt_session *iter; + struct ltt_session *iter, *tmp; lock_session_list(); - cds_list_for_each_entry(iter, <t_session_list.head, list) { + cds_list_for_each_entry_safe(iter, tmp, <t_session_list.head, list) { if (strcmp(iter->name, name) == 0) { DBG("Destroying session %s", iter->name); del_session_list(iter); diff --git a/ltt-sessiond/trace.c b/ltt-sessiond/trace.c index b6138f8f5..1509edacd 100644 --- a/ltt-sessiond/trace.c +++ b/ltt-sessiond/trace.c @@ -311,8 +311,8 @@ void trace_destroy_kernel_event(struct ltt_kernel_event *event) void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel) { - struct ltt_kernel_stream *stream; - struct ltt_kernel_event *event; + struct ltt_kernel_stream *stream, *stmp; + struct ltt_kernel_event *event, *etmp; DBG("[trace] Closing channel fd %d", channel->fd); /* Close kernel fd */ @@ -322,12 +322,12 @@ void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel) free(channel->channel); /* For each stream in the channel list */ - cds_list_for_each_entry(stream, &channel->stream_list.head, list) { + cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) { trace_destroy_kernel_stream(stream); } /* For each event in the channel list */ - cds_list_for_each_entry(event, &channel->events_list.head, list) { + cds_list_for_each_entry_safe(event, etmp, &channel->events_list.head, list) { trace_destroy_kernel_event(event); } @@ -349,7 +349,7 @@ void trace_destroy_kernel_metadata(struct ltt_kernel_metadata *metadata) void trace_destroy_kernel_session(struct ltt_kernel_session *session) { - struct ltt_kernel_channel *channel; + struct ltt_kernel_channel *channel, *ctmp; DBG("[trace] Closing session fd %d", session->fd); /* Close kernel fds */ @@ -363,7 +363,7 @@ void trace_destroy_kernel_session(struct ltt_kernel_session *session) trace_destroy_kernel_metadata(session->metadata); } - cds_list_for_each_entry(channel, &session->channel_list.head, list) { + cds_list_for_each_entry_safe(channel, ctmp, &session->channel_list.head, list) { trace_destroy_kernel_channel(channel); }