gststructure: Fix gst_structure_take ownership handling
The old code would leave a dangling pointer in oldstr_ptr
if two threads
attempted to take the same structure into the same location at the same
time:
- First
oldstr == newstr
check (before the loop) fails. - Compare-and-exchange fails, due to a second thread completing the
same
gst_structure_take
. - Second
oldstr == newstr
check (in the loop) succeeds, loop breaks. -
oldstr
check succeeds, old structure gets freed. -
oldstr_ptr
now contains a dangling pointer.
This shouldn't happen in code that handles ownership sanely, so check that we don't try to do this and complain loudly.
Also simplify the function by using a do
-while
loop, like
gst_mini_object_take
.