mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-03-11 16:35:33 +00:00
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:
parent
3edb832f76
commit
a7f4c3c15c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ check_sensor_timers();
|
|||
void
|
||||
reschedule_sensor_read();
|
||||
|
||||
void
|
||||
bool
|
||||
init_sensor_framework();
|
||||
void
|
||||
start_sensor_framework();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -45,7 +45,7 @@ static char *uart_device = "/dev/ttyS2";
|
|||
static int baudrate = B115200;
|
||||
#endif
|
||||
|
||||
extern void
|
||||
extern bool
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
|
@ -525,7 +525,9 @@ iwasm_main(int argc, char *argv[])
|
|||
|
||||
hal_init();
|
||||
|
||||
init_sensor_framework();
|
||||
if (!init_sensor_framework()) {
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
// timer manager
|
||||
init_wasm_timer();
|
||||
|
@ -545,6 +547,8 @@ iwasm_main(int argc, char *argv[])
|
|||
|
||||
exit_wasm_timer();
|
||||
exit_sensor_framework();
|
||||
|
||||
fail2:
|
||||
wgl_exit();
|
||||
exit_connection_framework();
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "display.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
extern void
|
||||
extern bool
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
|
|
|
@ -43,7 +43,7 @@ static char *uart_device = "/dev/ttyS2";
|
|||
static int baudrate = B115200;
|
||||
#endif
|
||||
|
||||
extern void
|
||||
extern bool
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
|
@ -505,7 +505,9 @@ iwasm_main(int argc, char *argv[])
|
|||
extern void display_SDL_init();
|
||||
display_SDL_init();
|
||||
|
||||
init_sensor_framework();
|
||||
if (!init_sensor_framework()) {
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
// timer manager
|
||||
init_wasm_timer();
|
||||
|
@ -525,6 +527,8 @@ iwasm_main(int argc, char *argv[])
|
|||
|
||||
exit_wasm_timer();
|
||||
exit_sensor_framework();
|
||||
|
||||
fail2:
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <drivers/uart.h>
|
||||
#include <device.h>
|
||||
|
||||
extern void
|
||||
extern bool
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
|
|
|
@ -45,7 +45,7 @@ static char *uart_device = "/dev/ttyS2";
|
|||
static int baudrate = B115200;
|
||||
#endif
|
||||
|
||||
extern void
|
||||
extern bool
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
|
@ -525,7 +525,10 @@ iwasm_main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* sensor framework */
|
||||
init_sensor_framework();
|
||||
if (!init_sensor_framework()) {
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
/* add the sys sensor objects */
|
||||
add_sys_sensor("sensor_test1", "This is a sensor for test", 0, 1000,
|
||||
read_test_sensor, config_test_sensor);
|
||||
|
@ -548,6 +551,8 @@ iwasm_main(int argc, char *argv[])
|
|||
|
||||
exit_wasm_timer();
|
||||
exit_sensor_framework();
|
||||
|
||||
fail2:
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
|
|
|
@ -808,7 +808,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (g_conn_fd == -1) {
|
||||
if (init() != 0) {
|
||||
if ((init() != 0)
|
||||
|| (g_conn_fd == -1)) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user