Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Fix to cellular sockets clean-up introduce by heap accounting change.
Browse files Browse the repository at this point in the history
Commit 3ffd36f introduced improved accounting for the sockets tests but, in so doing, it introduced a problem for cellular: uCellSockCleanup() was modified to remove the URCs, however that should _not_ be done until all sockets are closed, i.e. it should be done in uCellSockDeinit() instead (which is called by uSockCleanUp() once all sockets are closed).

Thanks to eeFLis for highlighting this.
  • Loading branch information
RobMeades committed Mar 21, 2024
1 parent 6507777 commit bf58552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cell/api/u_cell_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int32_t uCellSockClose(uDeviceHandle_t cellHandle,
/** Clean-up. This function should be called when
* there is no socket activity, either locally or from
* the remote host, in order to free memory occupied
* by closed sockets.
* by sockets that have been closed.
*
* @param cellHandle the handle of the cellular instance.
*/
Expand Down
25 changes: 13 additions & 12 deletions cell/src/u_cell_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,18 @@ int32_t uCellSockInitInstance(uDeviceHandle_t cellHandle)
// Deinitialise the cellular sockets layer.
void uCellSockDeinit()
{
uCellPrivateInstance_t *pInstance = gpUCellPrivateInstanceList;

if (gInitialised) {
// Nothing to do; URCs are removed by clean-up function
while (pInstance != NULL) {
// Remove the URCs
for (size_t x = 0; x < sizeof(gUrcHandlers) /
sizeof(gUrcHandlers[0]); x++) {
uAtClientRemoveUrcHandler(pInstance->atHandle,
gUrcHandlers[x].pPrefix);
}
pInstance = pInstance->pNext;
}
gInitialised = false;
}
}
Expand Down Expand Up @@ -937,17 +947,8 @@ int32_t uCellSockClose(uDeviceHandle_t cellHandle,
// Clean-up.
void uCellSockCleanup(uDeviceHandle_t cellHandle)
{
uCellPrivateInstance_t *pInstance;

pInstance = pUCellPrivateGetInstance(cellHandle);
if (pInstance != NULL) {
// Remove the URCs
for (size_t x = 0; x < sizeof(gUrcHandlers) /
sizeof(gUrcHandlers[0]); x++) {
uAtClientRemoveUrcHandler(pInstance->atHandle,
gUrcHandlers[x].pPrefix);
}
}
// Nothing to do: URCs are removed in uCellDeinit()
(void) cellHandle;
}

/* ----------------------------------------------------------------
Expand Down

0 comments on commit bf58552

Please sign in to comment.