Skip to content

Commit

Permalink
fix: leave null pointer if task init failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 26, 2023
1 parent abd4606 commit 7a681f7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/transport/multicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) {
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
ztm->_lease_task = task;
ztm->_lease_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) {
ztm->_lease_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
ztm->_lease_task = task;
ztm->_lease_task_running = true;
return _Z_RES_OK;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/multicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) {
int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._multicast._read_task = task;
zt->_transport._multicast._read_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) {
zt->_transport._multicast._read_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
zt->_transport._multicast._read_task = task;
zt->_transport._multicast._read_task_running = true;
return _Z_RES_OK;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/raweth/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ int8_t _zp_raweth_read(_z_transport_multicast_t *ztm) {
int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._raweth._read_task = task;
zt->_transport._raweth._read_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) {
zt->_transport._raweth._read_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
zt->_transport._raweth._read_task = task;
zt->_transport._raweth._read_task_running = true;
return _Z_RES_OK;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) {
int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._unicast._lease_task = task;
zt->_transport._unicast._lease_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) {
zt->_transport._unicast._lease_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
zt->_transport._unicast._lease_task = task;
zt->_transport._unicast._lease_task_running = true;
return _Z_RES_OK;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/unicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) {
int8_t _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._unicast._read_task = task;
zt->_transport._unicast._read_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) {
zt->_transport._unicast._read_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
zt->_transport._unicast._read_task = task;
zt->_transport._unicast._read_task_running = true;
return _Z_RES_OK;
}

Expand Down

0 comments on commit 7a681f7

Please sign in to comment.