summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemy Noel <mocramis@gmail.com>2018-04-14 10:18:59 +0200
committerRemy Noel <mocramis@gmail.com>2018-04-14 10:55:05 +0200
commit7f1d6dcb4317647a3fc06f7d95f751142d7c6f16 (patch)
treec3866a091dad1d761024b9f100b415a54c0b0a2e
parent49626c85923fafb6088616cbda005efd329d3c34 (diff)
test_perfmon_torture: fix names being copied from freed memory.
-rw-r--r--test/test_perfmon_torture.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/test/test_perfmon_torture.c b/test/test_perfmon_torture.c
index 763a5b5..7b54129 100644
--- a/test/test_perfmon_torture.c
+++ b/test/test_perfmon_torture.c
@@ -129,14 +129,30 @@ test_thread_toggle_monitor(struct test_thread *thread,
}
}
+static int
+test_thread_create_monitored_thread(struct thread **thread, size_t index,
+ void *arg)
+{
+ struct thread_attr attr;
+ char name[THREAD_NAME_SIZE];
+
+ snprintf(name, sizeof(name), THREAD_KERNEL_PREFIX
+ "test_monitored_thread:%zu", index);
+ thread_attr_init(&attr, name);
+ thread_attr_set_detached(&attr);
+
+ return thread_create(thread, &attr, test_thread_run, arg);
+}
+
static void
-test_thread_toggle_state(struct test_thread *thread,
+test_thread_toggle_state(size_t index,
struct threads_stats *stats)
{
int error;
- struct thread_attr attr;
struct perfmon_group *group;
+ struct test_thread *thread;
+ thread = test_threads[index];
group = thread->group;
switch (thread->state) {
@@ -152,11 +168,9 @@ test_thread_toggle_state(struct test_thread *thread,
}
error = perfmon_group_detach(group);
error_check(error, "perfmon_group_detach");
- thread_attr_init(&attr, thread->thread->name);
- thread_attr_set_detached(&attr);
thread->state = TEST_LAUNCHED;
- error = thread_create(&thread->thread, &attr, test_thread_run,
- thread);
+ error = test_thread_create_monitored_thread(&thread->thread, index,
+ thread);
error_check(error, "thread_recreate monitored");
error = perfmon_group_attach(group, thread->thread);
error_check(error, "perfmon_group_attach");
@@ -199,8 +213,7 @@ test_x15_test_control_run(void *arg)
/* only half of the threads may be stopped / restarted */
stopped_thread = (stopped_thread + 11) % ((nr_threads + 1) / 2);
- thread = test_threads[stopped_thread];
- test_thread_toggle_state(thread, &stats);
+ test_thread_toggle_state(stopped_thread, &stats);
test_wait();
if (!(++loop_since_status % TEST_NUM_LOOP_STATUS_PRINT)) {
@@ -222,8 +235,6 @@ static struct test_thread *
test_thread_create(size_t index)
{
struct test_thread *thread;
- char name[THREAD_NAME_SIZE];
- struct thread_attr attr;
int error;
thread = kmem_zalloc(sizeof(*thread));
@@ -232,13 +243,7 @@ test_thread_create(size_t index)
panic("thread allocation failed");
}
- snprintf(name, sizeof(name), THREAD_KERNEL_PREFIX
- "test_monitored_thread:%zu", index);
-
- thread_attr_init(&attr, name);
- thread_attr_set_detached(&attr);
- error = thread_create(&thread->thread, &attr,
- test_thread_run, thread);
+ error = test_thread_create_monitored_thread(&thread->thread, index, thread);
error_check(error, "thread_create");
error = perfmon_group_create(&thread->group);
error_check(error, "perfmon_group_create");