From e0f8208b80596eea62cf6ecabda043c6c6fab192 Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Mon, 13 Jul 2026 01:46:19 -0700 Subject: [PATCH] fix(modbus): handle malloc/pthread_create errors in set_skip_timer --- plugins/modbus/modbus_req.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/modbus/modbus_req.c b/plugins/modbus/modbus_req.c index b80a965a1..8266ae0d1 100644 --- a/plugins/modbus/modbus_req.c +++ b/plugins/modbus/modbus_req.c @@ -332,13 +332,23 @@ void set_skip_timer(uint8_t slave_id, uint32_t degrade_time) { degrade_timer_data_t *data = (degrade_timer_data_t *) malloc(sizeof(degrade_timer_data_t)); + if (data == NULL) { + skip[slave_id] = false; + return; + } + data->slave_id = slave_id; data->degrade_time = degrade_time; failed_cycles[slave_id] = 0; pthread_t timer_thread; - pthread_create(&timer_thread, NULL, degrade_timer, data); + int ret = pthread_create(&timer_thread, NULL, degrade_timer, data); + if (ret != 0) { + free(data); + skip[slave_id] = false; + return; + } pthread_detach(timer_thread); }