Fix app manager/framework issues reported by Coverity (#1155)

runtime_sensor.c: add return value check for os_mutex_init
                             fix find_sensor_client
sensor_mgr_ref.c: add return value check for init_sensor_framework
app_manager_host.c: add return value check for app_manager_host_init
module_wasm_app.c: add bh_assert for m_data
                                   fix mkdir potential issue
sample littlevgl/gui/simple: add return value check for init_sensor_framework
host_tool: add more check for g_conn_fd
This commit is contained in:
Xu Jun
2022-05-07 15:43:34 +08:00
committed by GitHub
parent 3edb832f76
commit a7f4c3c15c
11 changed files with 66 additions and 30 deletions

View File

@ -309,7 +309,13 @@ add_sys_sensor(char *name, char *description, int instance,
g_sys_sensors = s;
}
os_mutex_init(&s->lock);
if (os_mutex_init(&s->lock) != 0) {
if (s->description) {
wasm_runtime_free(s->description);
}
wasm_runtime_free(s->name);
wasm_runtime_free(s);
}
return s;
}
@ -358,6 +364,7 @@ find_sensor_client(sys_sensor_t *sensor, unsigned int client_id,
return c;
}
else {
prev = c;
c = c->next;
}
}

View File

@ -59,7 +59,7 @@ check_sensor_timers();
void
reschedule_sensor_read();
void
bool
init_sensor_framework();
void
start_sensor_framework();

View File

@ -106,12 +106,18 @@ cb_wakeup_thread()
void
set_sensor_reshceduler(void (*callback)());
void
bool
init_sensor_framework()
{
// init the mutext and conditions
os_cond_init(&cond);
os_mutex_init(&mutex);
/* init the mutext and conditions */
if (os_cond_init(&cond) != 0) {
return false;
}
if (os_mutex_init(&mutex) != 0) {
os_cond_destroy(&cond);
return false;
}
set_sensor_reshceduler(cb_wakeup_thread);
@ -119,6 +125,8 @@ init_sensor_framework()
app_mgr_sensor_event_callback);
wasm_register_cleanup_callback(sensor_cleanup_callback);
return true;
}
void

View File

@ -264,15 +264,21 @@ aee_host_msg_callback(void *msg, uint32_t msg_len)
bool
app_manager_host_init(host_interface *interface)
{
os_mutex_init(&host_lock);
if (os_mutex_init(&host_lock) != 0) {
return false;
}
memset(&recv_ctx, 0, sizeof(recv_ctx));
host_commu.init = interface->init;
host_commu.send = interface->send;
host_commu.destroy = interface->destroy;
if (host_commu.init != NULL)
return host_commu.init();
if (host_commu.init != NULL) {
if (!host_commu.init()) {
os_mutex_destroy(&host_lock);
return false;
}
}
return true;
}

View File

@ -207,10 +207,12 @@ app_instance_queue_callback(void *queue_msg, void *arg)
wasm_module_inst_t inst = (wasm_module_inst_t)arg;
module_data *m_data = app_manager_get_module_data(Module_WASM_App, inst);
wasm_data *wasm_app_data = (wasm_data *)m_data->internal_data;
int message_type = bh_message_type(queue_msg);
wasm_data *wasm_app_data;
int message_type;
bh_assert(m_data);
wasm_app_data = (wasm_data *)m_data->internal_data;
message_type = bh_message_type(queue_msg);
if (message_type < BASE_EVENT_MAX) {
switch (message_type) {
@ -410,16 +412,15 @@ wasm_app_prepare_wasi_dir(wasm_module_t module, const char *module_name,
p += module_name_len;
*p++ = '\0';
/* Create a wasi dir for the module */
if (stat(wasi_dir_buf, &st) == 0) {
/* exist, but is a regular file, not a dir */
if (st.st_mode & S_IFREG)
return false;
}
else {
/* not exist, create it */
if (mkdir(wasi_dir_buf, 0777) != 0)
return false;
if (mkdir(wasi_dir_buf, 0777) != 0) {
if (errno == EEXIST) {
/* Failed due to dir already exist */
if ((stat(wasi_dir_buf, &st) == 0) && (st.st_mode & S_IFDIR)) {
return true;
}
}
return false;
}
return true;