stream-thread fix memory corruption (#19367)
Costa Tsaousis committed
Jan 10, 2025 at 11:06 UTC
32c5b0a6b963f87c8a17bdf9454aee9e76c36113
1 file changed
+5
-3
src/streaming/stream-thread.c
+5
-3
@@ -312,14 +312,16 @@ static int set_pipe_size(int pipe_fd __maybe_unused, int new_size) {
312
313
// --------------------------------------------------------------------------------------------------------------------
314
315
-static void stream_thread_messages_resize_unsafe(struct stream_thread *sth) {
315
+static void stream_thread_messages_resize(struct stream_thread *sth) {
316
internal_fatal(sth->tid != gettid_cached(), "Function %s() should only be used by the dispatcher thread", __FUNCTION__ );
317
318
if(sth->nodes_count * 2 >= sth->messages.size) {
319
+ spinlock_lock(&sth->messages.spinlock);
320
size_t new_size = MAX(sth->messages.size * 2, sth->nodes_count * 2);
321
sth->messages.array = reallocz(sth->messages.array, new_size * sizeof(*sth->messages.array));
322
sth->messages.copy = reallocz(sth->messages.copy, new_size * sizeof(*sth->messages.copy));
323
sth->messages.size = new_size;
324
+ spinlock_unlock(&sth->messages.spinlock);
325
}
326
}
327
@@ -513,11 +515,11 @@ void *stream_thread(void *ptr) {
515
if(now_ut - last_dequeue_ut >= 100 * USEC_PER_MS) {
516
worker_is_busy(WORKER_STREAM_JOB_DEQUEUE);
517
518
+ stream_thread_messages_resize(sth);
519
+
520
// move any pending hosts in the inbound queue, to the running list
521
spinlock_lock(&sth->queue.spinlock);
522
519
- stream_thread_messages_resize_unsafe(sth);
520
-
523
stream_thread_process_waiting_list_unsafe(sth, now_ut);
524
// stream_receiver_move_entire_queue_to_running_unsafe(sth);
525