Skip to content

Commit 0b27c91

Browse files
committed
Fix SharedPtr::reset
SharedPtr::reset did not actually set the stored pointer value. Correct this, with other minor tidies: * Ensure counter is set to NULL if pointer is reset to NULL * Be consistent about not clearing pointers in decrement_counter().
1 parent a4ed473 commit 0b27c91

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

platform/SharedPtr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ class SharedPtr {
145145
// Clean up by decrementing counter
146146
decrement_counter();
147147

148+
_ptr = ptr;
148149
if (ptr != NULL) {
149150
// Allocate counter on the heap, so it can be shared
150151
_counter = new uint32_t;
151152
*_counter = 1;
153+
} else {
154+
_counter = NULL;
152155
}
153156
}
154157

@@ -226,16 +229,16 @@ class SharedPtr {
226229
/**
227230
* @brief Decrement reference counter.
228231
* @details If count reaches zero, free counter and delete object pointed to.
232+
* Does not modify our own pointers - assumption is they will be overwritten
233+
* or destroyed immediately afterwards.
229234
*/
230235
void decrement_counter()
231236
{
232237
if (_ptr != NULL) {
233238
uint32_t new_value = core_util_atomic_decr_u32(_counter, 1);
234239
if (new_value == 0) {
235240
delete _counter;
236-
_counter = NULL;
237241
delete _ptr;
238-
_ptr = NULL;
239242
}
240243
}
241244
}

0 commit comments

Comments
 (0)