summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-11-29 11:27:38 +0800
committeryangwei <[email protected]>2023-11-30 09:53:27 +0800
commit7fc028c7690e1a2a81626f245609b20e38b2f8df (patch)
tree359c13874bc3b4d4272ec62f58c5e807095b8791
parent87626a3930906f99458bdc3aa83c6f86ddeeffd8 (diff)
🐞fix(stellar_init): enhanced error handling for toml initialization
-rw-r--r--src/adapter/adapter.c10
-rw-r--r--src/adapter/session_manager.c2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c
index 9523833..224a27a 100644
--- a/src/adapter/adapter.c
+++ b/src/adapter/adapter.c
@@ -55,6 +55,7 @@ static struct plugin_specific *load_plugin_specs(const char *toml_conf_path, int
return NULL;
}
toml_array_t* plugin_array = toml_array_in(conf, "plugin");
+ if(plugin_array==NULL)return NULL;
*spec_num = toml_array_nelem(plugin_array);
struct plugin_specific* plugins = CALLOC(struct plugin_specific, *spec_num);
@@ -103,14 +104,17 @@ struct stellar *stellar_init(const char *toml_conf_path)
{
int spec_num;
struct plugin_specific *specs = load_plugin_specs(toml_conf_path, &spec_num);
- if(specs == NULL || spec_num == 0)
+ if(spec_num < 0)
{
return NULL;
}
struct stellar *st = CALLOC(struct stellar, 1);
struct plugin_specific_inernal spec_internal={};
- utarray_new(st->plugin_specs_array,&plugin_specs_icd);
- utarray_reserve(st->plugin_specs_array, spec_num);
+ if(spec_num > 0)
+ {
+ utarray_new(st->plugin_specs_array,&plugin_specs_icd);
+ utarray_reserve(st->plugin_specs_array, spec_num);
+ }
st->intrinsic_session_event_exdata_idx=stellar_session_get_ex_new_index(st, "__STELLAR__", exdata_plugin_rt_free, NULL);
for(int i = 0; i < spec_num; i++)
{
diff --git a/src/adapter/session_manager.c b/src/adapter/session_manager.c
index d4315ac..b552875 100644
--- a/src/adapter/session_manager.c
+++ b/src/adapter/session_manager.c
@@ -305,6 +305,7 @@ void session_dispatch(struct session *sess, enum session_state state, struct pa
struct session_event *intrinsic_events = (struct session_event *)session_get_ex_data(sess, sess->st->intrinsic_session_event_exdata_idx);
struct session_event *p = NULL;
if(sess->st->plugin_specs_array == NULL)return;
+ if(sess->st->intrinsic_session_event_schema_array == NULL)return;
unsigned int len = utarray_len(sess->st->intrinsic_session_event_schema_array);
sess->state = state;
// TODO: improve state to events logic
@@ -326,6 +327,7 @@ void session_plugin_detach_others(struct session *sess, int plugin_id)
{
struct session_event *intrinsic_events = (struct session_event *)session_get_ex_data(sess, sess->st->intrinsic_session_event_exdata_idx);
if(sess->st->plugin_specs_array == NULL)return;
+ if(sess->st->intrinsic_session_event_schema_array == NULL)return;
unsigned int len = utarray_len(sess->st->intrinsic_session_event_schema_array);
for(unsigned int i = 0; i < len; i++)
{