Skip to content

Commit 6684570

Browse files
authored
Merge pull request #9580 from kjbracey-arm/sharedptr_reset
Fix SharedPtr::reset
2 parents e9648dd + 0b27c91 commit 6684570

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

@@ -223,15 +226,15 @@ class SharedPtr {
223226
/**
224227
* @brief Decrement reference counter.
225228
* @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.
226231
*/
227232
void decrement_counter()
228233
{
229234
if (_ptr != NULL) {
230235
if (core_util_atomic_decr_u32(_counter, 1) == 0) {
231236
delete _counter;
232-
_counter = NULL;
233237
delete _ptr;
234-
_ptr = NULL;
235238
}
236239
}
237240
}

0 commit comments

Comments
 (0)