summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniubinghui <[email protected]>2024-08-30 16:30:47 +0800
committerniubinghui <[email protected]>2024-08-30 16:30:47 +0800
commitd45d25e225ab0ddd1b77072cbb866ebe14a68b71 (patch)
treea5c0668c1fb28ede2230af11954d5e9b170344ae
parent59b8dfa2a263539acbebc591cdc9f27434509918 (diff)
【修改】BugFix:在一些情况下,realloc内存未初始化可能会导致加载失败
-rw-r--r--src/lua_plugin_manage.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lua_plugin_manage.c b/src/lua_plugin_manage.c
index 27e1df3..1686ff0 100644
--- a/src/lua_plugin_manage.c
+++ b/src/lua_plugin_manage.c
@@ -318,6 +318,9 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init(
return NULL;
if (__glibc_unlikely((specific_count && !specific) || (specific_count < 0)))
return NULL;
+#ifdef LUAPLUGIN_BASIC_UNITTEST
+ LOGDEBUG("get specific count is %d", specific_count);
+#endif
struct lua_plugin_manage_schema *new_schema = (struct lua_plugin_manage_schema *)calloc(1, sizeof(struct lua_plugin_manage_schema));
if (__glibc_unlikely(!new_schema))
@@ -331,6 +334,9 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init(
utarray_new(new_schema->message_mq_array, &lua_message_mq_icd);
int thread_count = stellar_get_worker_thread_num(st);
+#ifdef LUAPLUGIN_BASIC_UNITTEST
+ LOGDEBUG("get stellar thread num is %d", thread_count);
+#endif
new_schema->state_count = thread_count;
/* 为后续待创建的lua_State预分配内存 */
new_schema->thread_state = (lua_State **)calloc(thread_count, sizeof(lua_State *));
@@ -425,6 +431,8 @@ int lua_plugin_manage_load_one_specific(
schema->model = (struct lua_model *)realloc(schema->model, (schema->model_count + 1) * sizeof(struct lua_model));
schema->model_count += 1;
}
+ /* BugFix: 在某些情况下, 该内存未初始化会导致加载失败 */
+ memset(&schema->model[schema->model_count - 1], 0, sizeof(struct lua_model));
for (int thread_index = 0; thread_index < schema->state_count; ++thread_index)
{
@@ -459,6 +467,9 @@ int lua_plugin_manage_load_one_specific(
LOGERROR("create plugin statistics failed");
return -1;
}
+#ifdef LUAPLUGIN_BASIC_UNITTEST
+ debug_lua_plugin_manage_schema(schema);
+#endif
return 0;
}