Merge pull request #13098 from AriParkkila/cell-free-stack

Cellular: Fix CellularContext destructor memory leak
pull/13135/head
Martin Kojtal 2020-06-17 13:24:17 +02:00 committed by GitHub
commit b1629b7e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -109,7 +109,7 @@ public:
class my_AT_CTX : public AT_CellularContext {
public:
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn), _st(at, *get_device())
AT_CellularContext(at, device, apn)
{
AT_CellularDevice_stub::supported_bool = false;
}
@ -117,8 +117,12 @@ public:
virtual NetworkStack *get_stack()
{
return &_st;
if (!_stack) {
_stack = new my_stack(_at, *get_device());
}
return _stack;
}
virtual uint32_t get_timeout_for_operation(ContextOperation op) const
{
return 10;
@ -137,24 +141,23 @@ public:
{
deactivate_non_ip_context();
}
my_stack _st;
};
class my_AT_CTXIPV6 : public AT_CellularContext {
public:
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn), _st(at, *get_device()) {}
AT_CellularContext(at, device, apn) {}
virtual ~my_AT_CTXIPV6() {}
virtual NetworkStack *get_stack()
{
return &_st;
if (!_stack) {
_stack = new my_stack(_at, *get_device());
}
}
virtual uint32_t get_timeout_for_operation(ContextOperation op) const
{
return 10;
}
my_stack _st;
};
class def_AT_CTX : public AT_CellularContext {

View File

@ -17,6 +17,7 @@
#ifndef _CELLULARCONTEXT_H_
#define _CELLULARCONTEXT_H_
#include "NetworkStack.h"
#include "CellularInterface.h"
#include "CellularDevice.h"
#include "CellularUtil.h"
@ -117,7 +118,15 @@ protected:
// friend of CellularDevice, so it's the only way to close or delete this class.
friend class CellularDevice;
CellularContext();
virtual ~CellularContext() {}
virtual ~CellularContext()
{
#if !NSAPI_PPP_AVAILABLE
if (_stack) {
delete _stack;
}
#endif
}
public: // from NetworkInterface
virtual nsapi_error_t set_blocking(bool blocking) = 0;
virtual NetworkStack *get_stack() = 0;