【修改】BugFix:在一些情况下,realloc内存未初始化可能会导致加载失败
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user