u-blox / ubxlib

Portable C libraries which provide APIs to build applications with u-blox products and services. Delivered as add-on to existing microcontroller and RTOS SDKs.
Apache License 2.0
313 stars 98 forks source link

cell: Fix memory leak in case uAtClientUnlock returns failure #283

Closed se-stefan closed 1 month ago

se-stefan commented 1 month ago

In the case uAtClientUnlock() in u_cell_http.c returned a failure code, the memory for pHttpInstance was not released.

The issue appeared rarely in combination with bad cellular coverage (disconnect during transmission attempt). The log files in indicated a memory leak:

01.01.00 01:42:39.956 DBG WDG [pool] malloc 72B @0x20001708   > pContext
01.01.00 01:42:39.956 DBG WDG [pool] malloc 80B @0x20001758   > pContext->semaphoreHandle
01.01.00 01:42:39.956 DBG WDG [pool] malloc 4B @0x20000cf8    > pContext->pPriv
01.01.00 01:42:39.957 DBG WDG [pool] malloc 1025B @0x20007b18 > pServerNameTemp
01.01.00 01:42:39.957 DBG WDG [pool] malloc 276B @0x20003af8  > pHttpInstance -> never released!
// uAtClientUnlock() returned -10 in u_cell_http.c
01.01.00 01:42:40.100 DBG WDG [pool] free @0x20007b18         < pServerNameTemp
01.01.00 01:42:40.100 DBG WDG [pool] free @0x20000cf8         < pContext->pPriv
01.01.00 01:42:40.100 DBG WDG [pool] free @0x20001758         < pContext->semaphoreHandle
01.01.00 01:42:40.101 DBG WDG [pool] free @0x20001708         < pContext