File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -145,10 +145,13 @@ class SharedPtr {
145
145
// Clean up by decrementing counter
146
146
decrement_counter ();
147
147
148
+ _ptr = ptr;
148
149
if (ptr != NULL ) {
149
150
// Allocate counter on the heap, so it can be shared
150
151
_counter = new uint32_t ;
151
152
*_counter = 1 ;
153
+ } else {
154
+ _counter = NULL ;
152
155
}
153
156
}
154
157
@@ -223,15 +226,15 @@ class SharedPtr {
223
226
/* *
224
227
* @brief Decrement reference counter.
225
228
* @details If count reaches zero, free counter and delete object pointed to.
229
+ * Does not modify our own pointers - assumption is they will be overwritten
230
+ * or destroyed immediately afterwards.
226
231
*/
227
232
void decrement_counter ()
228
233
{
229
234
if (_ptr != NULL ) {
230
235
if (core_util_atomic_decr_u32 (_counter, 1 ) == 0 ) {
231
236
delete _counter;
232
- _counter = NULL ;
233
237
delete _ptr;
234
- _ptr = NULL ;
235
238
}
236
239
}
237
240
}
You can’t perform that action at this time.
0 commit comments