From 72618ba82af966bbde6fda49905f6b2b6fa25fd0 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 6 Oct 2021 17:35:07 +0300 Subject: lib: fix incorrect thread management The current code passes an address of a local variable to `thread_add_read` which stores it into `thread->ref` by the lib. The next time the thread callback is executed, the lib stores NULL into the `thread->ref` which means it writes into some random memory on the stack. To fix this, we should pass a pointer to the vector entry to the lib. Signed-off-by: Igor Ryzhov --- lib/vector.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/vector.c') diff --git a/lib/vector.c b/lib/vector.c index 565c49fd59..4af564a82f 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -123,6 +123,17 @@ int vector_set_index(vector v, unsigned int i, void *val) return i; } +/* Make a specified index slot active and return its address. */ +void **vector_get_index(vector v, unsigned int i) +{ + vector_ensure(v, i); + + if (v->active <= i) + v->active = i + 1; + + return &v->index[i]; +} + /* Look up vector. */ void *vector_lookup(vector v, unsigned int i) { -- cgit v1.2.3