@@ -41,20 +41,18 @@ M2MBase& M2MBase::operator=(const M2MBase& other)
41
41
_register_uri = other._register_uri ;
42
42
_uri_path = other._uri_path ;
43
43
_max_age = other._max_age ;
44
- if (_token) {
45
- free (_token);
46
- _token = NULL ;
47
- _token_length = 0 ;
48
- }
44
+
45
+ free (_token);
46
+ _token = NULL ;
47
+
49
48
_token_length = other._token_length ;
50
49
if (other._token ) {
51
50
_token = alloc_string_copy (other._token , other._token_length );
52
51
}
53
52
54
- if (_report_handler) {
55
- delete _report_handler;
56
- _report_handler = NULL ;
57
- }
53
+ delete _report_handler;
54
+ _report_handler = NULL ;
55
+
58
56
if (other._report_handler ) {
59
57
_report_handler = new M2MReportHandler (*other._report_handler );
60
58
}
@@ -121,15 +119,8 @@ M2MBase::M2MBase(const String & resource_name,
121
119
122
120
M2MBase::~M2MBase ()
123
121
{
124
- if (_report_handler) {
125
- delete _report_handler;
126
- _report_handler = NULL ;
127
- }
128
- if (_token) {
129
- free (_token);
130
- _token = NULL ;
131
- _token_length = 0 ;
132
- }
122
+ delete _report_handler;
123
+ free (_token);
133
124
}
134
125
135
126
void M2MBase::set_operation (M2MBase::Operation opr)
@@ -188,20 +179,16 @@ void M2MBase::set_under_observation(bool observed,
188
179
_report_handler->set_under_observation (observed);
189
180
}
190
181
} else {
191
- if (_report_handler) {
192
- delete _report_handler;
193
- _report_handler = NULL ;
194
- }
182
+ delete _report_handler;
183
+ _report_handler = NULL ;
195
184
}
196
185
}
197
186
198
187
void M2MBase::set_observation_token (const uint8_t *token, const uint8_t length)
199
188
{
200
- if (_token) {
201
- free (_token);
202
- _token = NULL ;
203
- _token_length = 0 ;
204
- }
189
+ free (_token);
190
+ _token = NULL ;
191
+ _token_length = 0 ;
205
192
206
193
if ( token != NULL && length > 0 ) {
207
194
_token = alloc_string_copy ((uint8_t *)token, length);
@@ -279,10 +266,8 @@ M2MBase::Observation M2MBase::observation_level() const
279
266
void M2MBase::get_observation_token (uint8_t *&token, uint32_t &token_length)
280
267
{
281
268
token_length = 0 ;
282
- if (token) {
283
- free (token);
284
- token = NULL ;
285
- }
269
+ free (token);
270
+
286
271
token = alloc_string_copy ((uint8_t *)_token, _token_length);
287
272
if (token) {
288
273
token_length = _token_length;
0 commit comments