From 4d8d73f57cf2e4b679bec6cd0daf07939e527a38 Mon Sep 17 00:00:00 2001 From: Thiago Alves Date: Thu, 11 Sep 2025 13:15:12 -0400 Subject: [PATCH] Fix python loader cmd stack variable --- webserver/core/python_loader.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/webserver/core/python_loader.cpp b/webserver/core/python_loader.cpp index 83f6764..af9b6e2 100644 --- a/webserver/core/python_loader.cpp +++ b/webserver/core/python_loader.cpp @@ -161,10 +161,23 @@ int python_block_loader(const char *script_name, const char *script_content, cha close(shm_in_fd); close(shm_out_fd); + char *cmd = malloc(512); + if (cmd == NULL) + { + snprintf(log_msg, sizeof(log_msg), "malloc failed for cmd buffer\n"); + openplc_log(log_msg); + return -1; + } + snprintf(cmd, 512, "python3 -u %s 2>&1", script_name); + pthread_t tid; - char cmd[512]; - snprintf(cmd, sizeof(cmd), "python3 -u %s 2>&1", script_name); - pthread_create(&tid, NULL, runner_thread, (void *)cmd); + if (pthread_create(&tid, NULL, runner_thread, cmd) != 0) + { + snprintf(log_msg, sizeof(log_msg), "pthread_create failed: %s\n", strerror(errno)); + openplc_log(log_msg); + free(cmd); + return -1; + } pthread_detach(tid); return 0;