mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #13098 from AriParkkila/cell-free-stack
Cellular: Fix CellularContext destructor memory leakpull/13135/head
commit
b1629b7e59
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue