Skip to content

Commit

Permalink
fix: add error log if buffer are not allocated
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 24, 2024
1 parent 528d89e commit a99b652
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transport/multicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,13 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t
#else
entry->_dbuf_reliable = _z_wbuf_make(Z_FRAG_MAX_SIZE, false);
entry->_dbuf_best_effort = _z_wbuf_make(Z_FRAG_MAX_SIZE, false);

if ((_z_wbuf_capacity(&entry->_dbuf_reliable) != Z_FRAG_MAX_SIZE) ||
(_z_wbuf_capacity(&entry->_dbuf_best_effort) != Z_FRAG_MAX_SIZE)) {
_Z_ERROR("Not enough memory to allocate peer defragmentation buffers!");
}
#endif
#endif

// Update lease time (set as ms during)
entry->_lease = t_msg->_body._join._lease;
entry->_next_lease = entry->_lease;
Expand Down
1 change: 1 addition & 0 deletions src/transport/multicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl,
// Clean up the buffers if one of them failed to be allocated
if ((_z_wbuf_capacity(&ztm->_wbuf) != mtu) || (_z_zbuf_capacity(&ztm->_zbuf) != Z_BATCH_MULTICAST_SIZE)) {
ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
_Z_ERROR("Not enough memory to allocate transport tx rx buffers!");

#if Z_FEATURE_MULTI_THREAD == 1
zp_mutex_free(&ztm->_mutex_tx);
Expand Down
2 changes: 2 additions & 0 deletions src/transport/unicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo
if ((_z_wbuf_capacity(&zt->_transport._unicast._wbuf) != wbuf_size) ||
(_z_zbuf_capacity(&zt->_transport._unicast._zbuf) != zbuf_size)) {
ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
_Z_ERROR("Not enough memory to allocate transport tx rx buffers!");

#if Z_FEATURE_MULTI_THREAD == 1

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 2009 with no text in the supplied rule-texts-file Warning

misra violation 2009 with no text in the supplied rule-texts-file
zp_mutex_free(&zt->_transport._unicast._mutex_tx);
Expand All @@ -108,6 +109,7 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo
(_z_wbuf_capacity(&zt->_transport._unicast._dbuf_best_effort) != Z_IOSLICE_SIZE)) {
#endif
ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
_Z_ERROR("Not enough memory to allocate transport defragmentation buffers!");

_z_wbuf_clear(&zt->_transport._unicast._dbuf_reliable);
_z_wbuf_clear(&zt->_transport._unicast._dbuf_best_effort);
Expand Down

0 comments on commit a99b652

Please sign in to comment.