[PATCH 03/11] kernel-shark-qt: Avoid race condition in kshark_get_event_name_easy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Calling tep_data_event_from_type() is not thread-safe (potential
race condition). This patch protects the access to it by using the
mutex associated with the input file.

Signed-off-by: Yordan Karadzhov <ykaradzhov@xxxxxxxxxx>
---
 kernel-shark-qt/src/libkshark.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel-shark-qt/src/libkshark.c b/kernel-shark-qt/src/libkshark.c
index fa85171..89ae769 100644
--- a/kernel-shark-qt/src/libkshark.c
+++ b/kernel-shark-qt/src/libkshark.c
@@ -1147,7 +1147,18 @@ const char *kshark_get_event_name_easy(struct kshark_entry *entry)
 		}
 	}
 
+	/*
+	 * Calling tep_data_event_from_type() is not thread-safe (potential
+	 * race condition).
+	 * TODO: See if we can add a thread-safe version of the
+	 * function. For the time being use a mutex to protect the access.
+	 */
+	pthread_mutex_lock(&kshark_ctx->input_mutex);
+
 	event = tep_data_event_from_type(kshark_ctx->pevent, event_id);
+
+	pthread_mutex_unlock(&kshark_ctx->input_mutex);
+
 	if (event)
 		return event->name;
 
-- 
2.17.1





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux